sdut-2725-The Urge to Merge-状压DP
来源:互联网 发布:简单制图软件 编辑:程序博客网 时间:2024/06/05 10:22
把数组竖起来,从上往下走。
如果当前位置是竖着乘的,那么第一个点标记为1.否则标记为0.
样例最终的状态为:
0 0 1
0 1 0
1 0 0
0 0 0
#include<iostream>#include<cmath>#include<algorithm>#include<stdio.h>#include<string.h>#define max(a,b) ((a)>(b)?(a):(b))using namespace std;int maps[1010][11];int dp[1010][11];int pan(int x,int y){ int i; for(i=0;i<3;i++) { int tt=(1<<i); if((x&tt)&&(y&tt))return 0; } return 1;}int add(int x,int y,int z){ int ans=0; int ss[4]; int i; for(i=0;i<3;i++) { if(x&(1<<i))ss[i+1]=1; else ss[i+1]=0; } for(i=0;i<3;i++) { if(y&(1<<i)) { ans+=maps[z-1][i+1]*maps[z][i+1]; ss[i+1]=1; } } int t1,t2; t1=t2=0; if(ss[1]==0&&ss[2]==0)t1=maps[z][1]*maps[z][2]; if(ss[2]==0&&ss[3]==0)t2=maps[z][2]*maps[z][3]; ans+=max(t1,t2); return ans;}int main(){ int i,j,k,n; int cas=0; while(~scanf("%d",&n)&n) { cas++; memset(maps,0,sizeof(maps)); memset(dp,0,sizeof(dp)); for(i=1;i<=3;i++) { for(j=1;j<=n;j++) { scanf("%d",&maps[j][i]); } } for(i=1;i<=n;i++) { for(j=0;j<(1<<3);j++) { for(k=0;k<(1<<3);k++) { if(pan(j,k)) { dp[i][j]=max(dp[i-1][k]+add(j,k,i),dp[i][j]); } } } } int maxx=-1; for(j=0;j<(1<<3);j++) { maxx=max(maxx,dp[n][j]); } printf("Case %d: ",cas); cout<<maxx<<endl; }}
- sdut-2725-The Urge to Merge-状压DP
- UVAlive 6560 - The Urge to Merge(状压dp)
- 中国海洋大学第四届朗讯杯高级组 The Urge to Merge
- UESTC The Urge to Merge(状态压缩)
- Decorrelating Semantic Visual Attributes by Resisting the Urge to Share 论文笔记
- Decorrelating Semantic Visual Attributes by Resisting the Urge to Share 论文笔记
- SDUT 3565 Feed the monkey && sdut 2879 Colorful Cupcakes (dp)
- sdut oj 3665 Feed the monkey(dp)
- SDUT 3565 Feed the monkey(DP)
- SDUT 3565 Feed the monkey【Dp】
- sdut 3565 Feed the monkey dp
- To the Max (DP)
- sdut 2623 The number of steps (概率dp)
- DP::Poj1050 To the max
- poj1050 To the Max (dp)
- POJ1050 TO THE MAX [DP]
- 1050 To the Max DP
- poj1050 to the max (DP)
- Django 序列化与反序列化
- 关于输入法
- NSObject的常用方法
- NYOJ-264-国王的魔镜-2013年10月23日22:11:54
- LeetCode Palindrome Number
- sdut-2725-The Urge to Merge-状压DP
- 笔试题二:冒泡排序算法实现
- poj 1742 coins_多重背包
- 第十四周自由练习项目——随意输入数从大到小输出
- 递归算法-汉诺塔问题
- Java编码建议-1
- 数据结构课程设计(约瑟夫环)
- 笔试题三:带头节点head链表逆序
- 将win7电脑无线网变身WiFi热点,让手机、笔记本共享上网