ZOJ3471Most 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
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int inf=0x3f3f3f3f;
int pho[][];
int dp[<<];
int main()
{
int n;
scanf("%d",&n);
while(n)
{
int ans=-inf;
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
scanf("%d",&pho[i][j]);
}
}
for(int i=;i<(<<n);i++)
{
dp[i]=-inf;
}
int num;
for(int s=;s<(<<n);s++)
{
num=;
for(int i=;i<=n;i++)
{
if(s&(<<(i-)))
{
if(s==(<<(i-)))
{
for(int j=;j<=n;j++)
{
if(i==j)
continue;
dp[s]=max(dp[s],pho[j][i]);
}
}
else
{
for(int j=;j<=n;j++)
{
if((s&(<<(j-)))==)
{
dp[s]=max(dp[s],dp[s^(<<(i-))]+pho[j][i]);
}
}
}
}
else
{
num++;
}
}
if(num==)
{
ans=max(ans,dp[s]);
}
}
printf("%d\n",ans);
scanf("%d",&n);
}
}
ZOJ3471Most Powerful(状态压缩)的更多相关文章
- ZOJ - 3471 Most Powerful (状态压缩)
题目大意:有n种原子,两种原子相碰撞的话就会产生能量,当中的一种原子会消失. 问这n种原子能产生的能量最大是多少 解题思路:用0表示该原子还没消失.1表示该原子已经消失.那么就能够得到状态转移方程了 ...
- ACM学习历程—ZOJ3471 Most Powerful(dp && 状态压缩 && 记忆化搜索 && 位运算)
Description Recently, researchers on Mars have discovered N powerful atoms. All of them are differen ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- HDU 3605:Escape(最大流+状态压缩)
http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意:有n个人要去到m个星球上,这n个人每个人对m个星球有一个选择,即愿不愿意去,"Y" ...
- [HDU 4336] Card Collector (状态压缩概率dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡 ...
- HDU 4336 Card Collector (期望DP+状态压缩 或者 状态压缩+容斥)
题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率,每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 析:期望DP,是很容易看出来的,然后由 ...
- codeforces B - Preparing Olympiad(dfs或者状态压缩枚举)
B. Preparing Olympiad You have n problems. You have estimated the difficulty of the i-th one as inte ...
- NOIP2005过河[DP 状态压缩]
题目描述 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把独木桥上青蛙可能到达的点看成数 ...
- vijos1426兴奋剂检查(多维费用的背包问题+状态压缩+hash)
背景 北京奥运会开幕了,这是中国人的骄傲和自豪,中国健儿在运动场上已经创造了一个又一个辉煌,super pig也不例外……………… 描述 虽然兴奋剂是奥运会及其他重要比赛的禁药,是禁止服用的.但是运动 ...
- hoj2662 状态压缩dp
Pieces Assignment My Tags (Edit) Source : zhouguyue Time limit : 1 sec Memory limit : 64 M S ...
随机推荐
- 安卓新发布机制----app bundle
Android App Bundle是一种改进的应用程序打包方式,能大幅度减少应用体积 unity可以直接导出appbundle,只需要在导出的时候勾选 但是通常项目有sdk离不开java端,我这里是 ...
- rpm操作
--查找某个软件:abc rpm -qa |grep abc --删除某个软件:abc rpm -e --noscripts abc
- 如何为根分区扩容(centos7为例)
linux系统所有的文件都是存放在根分区中的,如果根分区容量即将耗尽,我们就需要给根分区扩容,我们可以使用lsblk命令来查看,系统的根分区实际是逻辑卷,所以想要扩展根分区只要将逻辑卷扩容就可以了.此 ...
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
1.nginx 配置模板 server { listen ; client_max_body_size 512M; proxy_set_header Connection ""; ...
- jmeter—获取当前时间(年、月、日),往前/往后n天
import java.util.Calendar; Calendar cal = Calendar.getInstance(); int day = cal.get(Calendar.DATE); ...
- HDU 1231 最大连续子序列 (动态规划)
最大连续子序列 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- windows10 AppStore安装 应用商店重新安装
点击左下角的搜索按钮,如下图所示 输入powershell,在结果中找到widows powershell应用,如下图所示 右键单击widows powershell应用,选择以管理员运行,如 ...
- javaScript学习总结(二)——jQuery插件的开发
概要 jQuery插件就是以jQuery库为基础衍生出来的库,jQuery插件的好处是封装功能,提高了代码的复用性,加快了开发速度,现在网络上开源的jQuery插件非常多,随着版本的不停迭代越来越稳定 ...
- Eclipse快速生成do while if 等方法
选中所需要加方法的代码 右键 选中 surrounded with选择你需要就可以了
- 机器学习-SVM-手写识别问题
机器学习-SVM-手写识别问题 这里我们解决的还是之前用KNN曾经解决过的手写识别问题(https://www.cnblogs.com/jiading/p/11622019.html),但相比于KNN ...