Most Powerful(ZOJ 3471状压dp)
题意:n个原子,两两相撞其中一个消失,产生能量,给出任意两原子相撞能产生的能量,求能产生的最大能量。
分析:dp[i]表示情况为i时产生的最大能量
/*#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = 1000000007;
int n,dp[2000],a[15][15];
void solve(){
memset(dp,0,sizeof(dp));
for(int i=(1<<n)-1;i>0;--i){
int maxv=0,m=i;
for(int j=0;j<n;++j){
if((m&1)==0){
int maxp=0,t=i;
for(int k=0;k<n;++k){
if((t&1)&&a[k][j]>maxp)
maxp=a[k][j];
t>>=1;
}
if(dp[i^(1<<j)]+maxp>maxv)
maxv=dp[i^(1<<j)]+maxp;
}
m>>=1;
}
dp[i]=maxv;
}
int maxpow=-1;
for(int i=0;i<n;++i){
if(maxpow<dp[(1<<i)])
maxpow=dp[(1<<i)];
//cout<<dp[(1<<i)]<<endl;
}
printf("%d\n",maxpow);
}
int main()
{
while(~scanf("%d",&n)){
if(n==0)break;
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
scanf("%d",&a[i][j]);
solve();
}
return 0;
}*/
//
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = 1000000007;
int dp[1100],n;
int power[15][15];
void solve(){
memset(dp,0,sizeof(dp));
int cas=(1<<n);
for(int i=0;i<cas;++i)
for(int j=0;j<n;++j){
if((i&(1<<j)))continue;
int maxv=-1;
for(int k=0;k<n;++k)
if((i&(1<<k))==0&&j!=k)
dp[i|(1<<j)]=max(dp[i|(1<<j)],dp[i]+power[k][j]);
}
int maxv=-1;
for(int i=0;i<cas;++i)
maxv=max(maxv,dp[i]);
printf("%d\n",maxv);
}
int main()
{
while(~scanf("%d",&n)){
if(n==0)break;
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
scanf("%d",&power[i][j]);
solve();
}
return 0;
}
Most Powerful(ZOJ 3471状压dp)的更多相关文章
- Problem Arrangement ZOJ - 3777(状压dp + 期望)
ZOJ - 3777 就是一个入门状压dp期望 dp[i][j] 当前状态为i,分数为j时的情况数然后看代码 有注释 #include <iostream> #include <cs ...
- ZOJ 3306 状压dp
转自:http://blog.csdn.net/a497406594/article/details/38442893 Kill the Monsters Time Limit: 7 Seconds ...
- ZOJ - 3777(状压dp)
The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem setter, Edward i ...
- Survival(ZOJ 2297状压dp)
题意:有n个怪,已知杀死第i个怪耗费的血和杀死怪恢复的血,和杀死boss耗的血,血量不能超过100,若过程中血小于0,则失败,问 是否能杀死boss(boss最后出现). 分析:就是求杀死n个怪后剩余 ...
- zoj 3812 状压dp
转载:http://blog.csdn.net/qian99/article/details/39138329 题意:给出n个物品,每个物品有两种属性Wi,Ti,有q组查询,每组查询要求在n个物品中选 ...
- Long Dominoes(ZOJ 2563状压dp)
题意:n*m方格用1*3的方格填充(不能重叠)求有多少种填充方法 分析:先想状态,但想来想去就是觉得不能覆盖所有情况,隔了一天,看看题解,原来要用三进制 0 表示横着放或竖放的最后一行,1表示竖放的中 ...
- Travel(HDU 4284状压dp)
题意:给n个城市m条路的网图,pp在城市1有一定的钱,想游览这n个城市(包括1),到达一个城市要一定的花费,可以在城市工作赚钱,但前提有工作证(得到有一定的花费),没工作证不能在该城市工作,但可以走, ...
- 【状压dp】Most Powerful
[ZOJ3471]Most Powerful Time Limit: 2 Seconds Memory Limit: 65536 KB Recently, researchers on Ma ...
- ZOJ 3723 (浙大月赛)状压DP
A了一整天~~~终于搞掉了. 真是血都A出来了. 题目意思很清楚,肯定是状压DP. 我们可以联系一下POJ 1185 炮兵阵地,经典的状压DP. 两道题的区别就在于,这道题的攻击是可以被X挡住的,而 ...
随机推荐
- VBScript 函数
Date/Time 函数 Conversion 函数 Format 函数 Math 函数 Array 函数 String 函数 其他函数 Date/Time 函数 函数 描述 CDate 把一个有效的 ...
- iptables 代理设置
代理: 开启转发:echo 1 > /proc/sys/net/ipv4/ip_forward iptables -t nat -A POSTROUTING -s 192.168.1.0/24 ...
- TopCoder 603 div1 & div2
div2 250pts MiddleCode 题意:s串长度为奇数时,将中间字符取掉并添加到t末尾:长度为偶数时,将中间两个较小的字符取掉并添加到末尾. 分析:直接做,学习了一下substr(s, p ...
- POJ1470 Closest Common Ancestors
LCA问题,用了离线的tarjan算法.输入输出参考了博客http://www.cnblogs.com/rainydays/archive/2011/06/20/2085503.htmltarjan算 ...
- 致诸位新程序员:来自Chuck Jazdzewski慈父般的忠告
记住这几句话,学无止境.(Never stop learning.)沟通至关重要.(Communication is critical.)履行承诺,胜过交付.(Under promise, over ...
- Intellij IDEA采用Maven+Spring MVC+Hibernate的架构搭建一个java web项目
原文:Java web 项目搭建 Java web 项目搭建 简介 在上一节java web环境搭建中,我们配置了开发java web项目最基本的环境,现在我们将采用Spring MVC+Spring ...
- tomcat 内存配置
在bin目录下的catalina.bat里添加如下代码: rem ----- Execute The Requested Command ------------------------------- ...
- 选择语句----switch case
今天学习了选择语句的 switch case是多选一的情况可以使用. 案例: //分别输入月份 几号 输出是今年的多少天 //每年的1,3,5,7,8,10,12月是31天 //今年的2月是28天 其 ...
- 写Java程序要体现面向对象
对于之前写的一篇文章现在想想存在不足之处,之前写的测试ArrayList和LinkedList的各项操作性能比较的程序没有体现面向对象的封装特性,所以,今天把代码重新写了一遍,其实改动的地 ...
- 今天晚上 中国互联网被Struts2漏洞血洗
Apache官方今天晚上发布安全公告(官方编号S2-032/CVE编号CVE-2016-3081),Apache Struts2服务在开启动态方法调用(DMI)的情况下,可以被远程执行任意命令,安全威 ...