题意: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)的更多相关文章

  1. Problem Arrangement ZOJ - 3777(状压dp + 期望)

    ZOJ - 3777 就是一个入门状压dp期望 dp[i][j] 当前状态为i,分数为j时的情况数然后看代码 有注释 #include <iostream> #include <cs ...

  2. ZOJ 3306 状压dp

    转自:http://blog.csdn.net/a497406594/article/details/38442893 Kill the Monsters Time Limit: 7 Seconds ...

  3. ZOJ - 3777(状压dp)

    The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem setter, Edward i ...

  4. Survival(ZOJ 2297状压dp)

    题意:有n个怪,已知杀死第i个怪耗费的血和杀死怪恢复的血,和杀死boss耗的血,血量不能超过100,若过程中血小于0,则失败,问 是否能杀死boss(boss最后出现). 分析:就是求杀死n个怪后剩余 ...

  5. zoj 3812 状压dp

    转载:http://blog.csdn.net/qian99/article/details/39138329 题意:给出n个物品,每个物品有两种属性Wi,Ti,有q组查询,每组查询要求在n个物品中选 ...

  6. Long Dominoes(ZOJ 2563状压dp)

    题意:n*m方格用1*3的方格填充(不能重叠)求有多少种填充方法 分析:先想状态,但想来想去就是觉得不能覆盖所有情况,隔了一天,看看题解,原来要用三进制 0 表示横着放或竖放的最后一行,1表示竖放的中 ...

  7. Travel(HDU 4284状压dp)

    题意:给n个城市m条路的网图,pp在城市1有一定的钱,想游览这n个城市(包括1),到达一个城市要一定的花费,可以在城市工作赚钱,但前提有工作证(得到有一定的花费),没工作证不能在该城市工作,但可以走, ...

  8. 【状压dp】Most Powerful

    [ZOJ3471]Most Powerful Time Limit: 2 Seconds      Memory Limit: 65536 KB Recently, researchers on Ma ...

  9. ZOJ 3723 (浙大月赛)状压DP

    A了一整天~~~终于搞掉了. 真是血都A出来了. 题目意思很清楚,肯定是状压DP. 我们可以联系一下POJ 1185  炮兵阵地,经典的状压DP. 两道题的区别就在于,这道题的攻击是可以被X挡住的,而 ...

随机推荐

  1. mysql的学习记录

    1 MySQL -h localhost -u UserName -p Password-h不写,默认为localhost注意:最好先MySQL -h localhost -u UserName -p ...

  2. spring 与 CXF 整合 webservice 出现error “Unable to locate Spring NamespaceHandler for XML schema namespace” 总结

    我试了多个版本的spring 发现 出现error : Unable to locate Spring NamespaceHandler for XML schema namespace 并非都是sp ...

  3. mysql InnoDB 索引小记

    0.索引结构 1).MyISAM与InnoDB索引结构比较,如下: 2).MyISAM的索引结构 主键索引和二级索引结构很像,叶子存储的都是索引以及数据存储的物理地址,其他节点存储的仅仅是索引信息.其 ...

  4. 李洪强iOS开发之Foundation框架—集合

    Foundation框架—集合 一.NSArray和NSMutableArray (一)NSArray不可变数组 (1)NSArray的基本介绍 NSArray是OC中使用的数组,是面向对象的,以面向 ...

  5. lintcode : 空格替换

    题目: 空格替换 设计一种方法,将一个字符串中的所有空格替换成 %20 .你可以假设该字符串有足够的空间来加入新的字符,且你得到的是“真实的”字符长度. 样例 对于字符串"Mr John S ...

  6. git Unstaged changes after reset

    转载:http://my.oschina.net/yuzn/blog/150275 相信大家都做过这个操作,就是本地做了修改后,不想提交,想恢复如初 git reset HEAD   这样的话,我们就 ...

  7. 确认某端口占用情况并结束相应进程(Windows)

    (1)确认某端口是否被占用 (2)通过查找对应的PID号,定位是哪一个进程在使用该端口 (3)通过PID号结束该进程 # 查找端口2000是否被占用C:\Users\tdcqma>netstat ...

  8. 使用Retrofit时出现 java.lang.IllegalArgumentException: URL query string "t={type}&p={page}&size={count}" must not have replace block. For dynamic query parameters use @Query.异常原因

    /** * Created by leo on 16/4/30. */ public interface GanchaiService { @GET("digest?t={type}& ...

  9. RMI

    Java RMI (Remote Method Invocation 远程方法调用)是用Java在JDK1.1中实现的,它大大增强了Java开发分布式应用的能力.Java作为一种风靡一时的网络开发语言 ...

  10. 用maven进行测试

    maven的重要职责之一就是自动运行单元测试,它通过maven-surefire-plugin与主流的单元测试框架junit和testng集成,并且能够自动生成丰富的结果报表. maven并不是一个单 ...