zoj3471 Most Powerful
Recently, researchers on Mars have discovered N powerful atoms. All of them are different. These atoms have some properties. When two of these atoms collide, one of them disappears and
a lot of power is produced. Researchers know the way every two atoms perform when collided and the power every two atoms can produce.
You are to write a program to make it most powerful, which means that the sum of power produced during all the collides is maximal.
Input
There are multiple cases. The first line of each case has an integer N (2 <= N <= 10), which means there are N atoms: A1, A2, ... , AN. Then N lines follow.
There are N integers in each line. The j-th integer on the i-th line is the power produced when Ai and Aj collide with Aj gone. All integers are positive and not larger than 10000.
The last case is followed by a 0 in one line.
There will be no more than 500 cases including no more than 50 large cases that N is 10.
Output
Output the maximal power these N atoms can produce in a line for each case.
Sample Input
2
0 4
1 0
3
0 20 1
12 0 1
1 10 0
0
Sample Output
4
22
题意是有n个气球,n的范围是1~n,每两个气球碰撞都会产生一定的能量,并且有一个气球会消失,问最后剩下一个气球的时候最多能产生多少能量。可以用状态压缩,设0表示气体存在,1表示气体消失,状态转移方程dp[state]=max{dp[state],dp[state']+a[i][j]}.
#include<stdio.h>
#include<string.h>
int a[15][15],dp[1500];
int max(int a,int b){
return a>b?a:b;
}
int main()
{
int n,m,i,j,s,ans;
while(scanf("%d",&n)!=EOF && n!=0)
{
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
scanf("%d",&a[i][j]);
}
}
memset(dp,0,sizeof(dp));
for(s=1;s<(1<<n);s++){
for(j=1;j<=n;j++){
if(s&(1<<(j-1))){
for(i=1;i<=n;i++){
if( !(s&(1<<(i-1))) ){
dp[s]=max(dp[s],dp[s-(1<<(j-1))]+a[i][j]);
}
}
}
}
}
ans=0;
for(i=1;i<=n;i++){
if(dp[(1<<n)-1-(1<<(i-1))]>ans)ans=dp[(1<<n)-1-(1<<(i-1))];
}
printf("%d\n",ans);
}
return 0;
}
zoj3471 Most Powerful的更多相关文章
- ACM学习历程—ZOJ3471 Most Powerful(dp && 状态压缩 && 记忆化搜索 && 位运算)
Description Recently, researchers on Mars have discovered N powerful atoms. All of them are differen ...
- 【状压dp】Most Powerful
[ZOJ3471]Most Powerful Time Limit: 2 Seconds Memory Limit: 65536 KB Recently, researchers on Ma ...
- HDOJ 3593 The most powerful force
树形DP / 泛化物品的背包...可以去看09年徐持衡论文<浅谈几类背包问题> The most powerful force Time Limit: 16000/8000 MS (Jav ...
- CodeForces 86D Powerful array(莫队+优化)
D. Powerful array time limit per test 5 seconds memory limit per test 256 megabytes input standard i ...
- hdu 4150 Powerful Incantation
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4150 Powerful Incantation Description Some dangerous ...
- D. Powerful array 莫队算法或者说块状数组 其实都是有点优化的暴力
莫队算法就是优化的暴力算法.莫队算法是要把询问先按左端点属于的块排序,再按右端点排序.只是预先知道了所有的询问.可以合理的组织计算每个询问的顺序以此来降低复杂度. D. Powerful array ...
- 10+ powerful debugging tricks with Visual Studio
10+ powerful debugging tricks with Visual Studio Original link : http://www.codeproject.com/Articles ...
- zoj 3471 Most Powerful
题目链接:zoj 3471 Most Powerful 作者:jostree 转载请说明出处 很经典的状态dp,使用i的二进制位表示粒子的状态,0表示存在,1表示不存在.dp[i]表示在状态i的情况 ...
- zoj 3471 Most Powerful(状态压缩dp)
Recently, researchers on Mars have discovered N powerful atoms. All of them are different. These ato ...
随机推荐
- 十一:WEB渗透必懂知识点
简述WEB层面上的漏洞以及类型,具体漏洞的危害等级, 如何形成以及如何发现 右边权重大于左边 CTF,SRC,红蓝对抗,实战 简要说明以上漏洞危害 简要说课以上漏洞等级划分 简要说明以上漏洞重点内容 ...
- 【Linux】云服务器部署宝塔linux控制面板环境
服务器购买及宝塔部署环境说明 简单记录 - 狂神的 服务器购买及宝塔部署环境说明 服务器如何购买 我们尽量趁打折的时候购买,比较便宜点!多看看有活动. 如果是学生,可以购买学生机, 学生机地址:htt ...
- 【Linux】md5sum 生产所有文件的md5值,并对照目标文件是否相同
现在加入有很多很多文件需要测试md5,想看下是否都传输成功了,如何批量生成文件的md5并且逐条对照呢? 下面来简单介绍下 md5sum这个命令有一个选项"-c" 这个选项的意思是c ...
- 大文件上传FTP
需求 将本地大文件通过浏览器上传到FTP服务器. 原有方法 将本地文件整个上传到浏览器,然后发送到node服务器,最后由node发送到FTP服务器. 存在问题 浏览器缓存有限且上传速率受网速影响,当文 ...
- LuoguP5075 [JSOI2012]分零食
题意 有\(A\)个人,\(m\)个糖,你可以选择一个\(k\),使第\(1\)$k$个人每个人至少得到一个糖,并且第$k+1$\(A\)个人都得不到糖.\(m\)个糖必须给完.对于每个方案都有一个欢 ...
- 输入12V,输出12V的限流芯片
随着手机充电电流的提升,和设备的多样化,USB限流芯片就随着需求的增加而越来越多,同时为了更好的保护电子设备,需要进行一路或者多路的负载进行限流. USB限流芯片,5V输入 1, PW1502,常使用 ...
- PAT练习num2-挖掘机技术哪家强
为了用事实说明挖掘机技术到底哪家强,PAT 组织了一场挖掘机技能大赛.现请你根据比赛结果统计出技术最强的那个学校. 输入格式: 输入在第 1 行给出不超过 1 的正整数 N,即参赛人数.随后 N 行, ...
- Numpy的一些学习记录
Numpy的一些记录 产生numpy.array的方式 import numpy as np arr1 = np.array([1, 2, 3]) print(arr1) arr2 = np.zero ...
- 【Python网络编程】epoll用法
epoll发展进程 此处添加一下select.poll历程及其优缺点 原理 使用步骤 Create an epoll object--创建1个epoll对象 Tell the epoll object ...
- UML 博客学习 后续继续完善
http://blog.csdn.net/monkey_d_meng/article/details/6005764 http://blog.csdn.net/badobad/article/det ...