ZOJ Most Powerful (状态压缩DP)
来源:互联网 发布:narcissu 知乎 编辑:程序博客网 时间:2024/05/19 23:03
题目点我点我点我
题目大意:有n种原子,两种原子相碰撞的话就会产生能量,其中的一种原子会消失。问这n种原子能产生的能量最大是多少。
思路:简单的状态压缩DP,我是用1代表灭,0代表存活。
状态 :dp[state], 状态为state时的最大能量
转移 :dp[state | (1 << j)] = max(dp[state | (1 << j)], dp[state] + a[i][j])
表示的是在state的情况下,用i原子去碰撞j原子,j原子消失所能得到的最大能量
边界 :dp[i] = 0;
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;#define inf 0x3f3f3f3fint dp[1<<11];int a[11][11];int n;int main(){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); while(scanf("%d",&n),n) { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { scanf("%d",&a[i][j]); } } memset(dp,0,sizeof(dp)); for(int state=0;state<(1<<n);state++) { for(int i=1;i<=n;i++) { if(state&(1<<i))continue; //1代表灭,0代表存活,保证第i个存活 for(int j=1;j<=n;j++) { if(i==j||state&(1<<j))continue; dp[state|(1<<j)]=max(dp[state|(1<<j)],dp[state]+a[i][j]); } } } int ans=0; for(int i=1;i<=n;i++) { ans=max(ans,dp[i]); } printf("%d\n",ans); } return 0;}
0 0
- ZOJ Most Powerful (状态压缩DP)
- zoj 3471 Most Powerful //状态压缩DP
- ZOJ 3471 Most Powerful 状态压缩DP
- zoj 3471 Most Powerful 状态压缩dp
- zoj 3471 Most Powerful (状态压缩dp)
- ZOJ 3471 Most Powerful(状态压缩DP)
- zoj 3471 Most Powerful(状态压缩+dp)
- ZOj 3471 Most Powerful 状态压缩DP
- ZOJ 3471Most Powerful(状态压缩DP)
- zoj 3471 Most Powerful(状态压缩DP)
- zoj 3471 Most Powerful (状态压缩dp~)
- ZOJ 3471 Most Powerful (状态压缩)
- zoj3471 Most Powerful(状态压缩dp)
- DP状态压缩:Most Powerful
- Zoj 3471 Most Powerful 状态压缩
- ZOJ - 3471 Most Powerful (状态压缩)
- ZOJ 3471 Most Powerful (状态压缩)
- Most Powerful (状态dp)
- Intellij IDEA 创建Web项目并在Tomcat中部署运行
- 联想Y470清灰大法
- 工作,一年了!
- 1013. Battle Over Cities (25)
- eclipse快捷键大全啦啦啦啦
- ZOJ Most Powerful (状态压缩DP)
- Spring定时任务的几种实现
- 新阶乘问题,有两个数a,b(a>=b),求a到b之间所有数的阶乘之和;数据有多组.
- 马化腾内部讲座:我们希望的产品经理是从技术晋升而来的
- 对List里的对象元素进行排序
- LeetCode Product of Array Except Self
- 踩坑记录(4)-DiskLruCache需要权限
- iOS 获得汉字拼音首字母
- c语言输出的%