POJ3254-Corn Fields(状压DP)
来源:互联网 发布:软件开发部门ios 编辑:程序博客网 时间:2024/05/20 06:05
题目链接:http://poj.org/problem?id=3254
思路:把每行的状态转化成一个二进制数,每个数代表一种放置方法,dp[i][j]=Σdp[i-1][k](k为满足条件的放置方法)。
#include<cstdio>using namespace std;const int MOD=1e8;int dp[13][(1<<12)+5];int a[13],b[(1<<12)+5];bool check(int i,int j)//判断是否符合条件{ return (((~a[i]) & b[j]) == 0 ? 1 :0);}int main(){ int n,m,num=0,ans=0; scanf("%d%d",&n,&m); for(int i = 0 ;i < n ;i++) { for(int j = 0 ;j < m ;j++) { int x; scanf("%d",&x); if(x) a[i] += (1<<j);//二进制数 } } for(int i = 0 ;i < (1<<m) ;i++) { if(((i & (i<<1))) == 0)//判断是否会出现相邻 b[num++] = i;//并添加到数组中 } for(int j = 0 ;j < num ;j++) { if(check(0,j)) dp[0][j] = 1; } for(int i = 1 ;i < n ;i++) { for(int j = 0 ;j < num ;j++) { if(!check(i,j)) continue; for(int k = 0 ;k < num ;k++) { if(check(i-1,k) && !(b[j] & b[k]))//b[j]&b[k]保证上下不连续 dp[i][j] += dp[i-1][k]; } } } for(int j = 0 ;j < num ;j++) { ans += dp[n-1][j]; ans %= MOD; } printf("%d\n",ans); return 0;}
0 0
- poj3254(Corn Fields)状压dp
- poj3254--Corn Fields(状压dp)
- poj3254 Corn Fields(状压dp)
- POJ3254-Corn Fields(状压DP)
- POJ3254:Corn Fields(状压dp入门)
- 【poj3254】Corn Fields(状压dp)
- Poj3254 Corn Fields (状压Dp)
- poj3254 Corn Fields(状压dp)
- POJ3254-Corn Fields(状压dp)
- poj3254:Corn Fields(状压DP)
- 【状压DP】Corn Fields POJ3254
- poj3254 Corn Fields 状压dp
- POJ3254-Corn Fields-状压DP
- poj3254 Corn Fields (状压dp)
- POJ3254 Corn Fields 【状压dp】
- POJ3254 Corn Fields(状压DP)
- POJ3254 Corn Fields(DP)
- 【DP】 poj3254 Corn Fields
- linux下MySQL安装及设置
- 如何解读Caffe源码
- 操作系统知识点
- poj 3608 Bridge Across Islands (计算几何)
- codeforces 189A. Cut Ribbon
- POJ3254-Corn Fields(状压DP)
- Python 报错IndentationError: unindent does not match any outer indentation level
- java实现快速排序
- jstl标签的用法(一)
- iOS8之后UIAlertView被弃用 UIAlertController成功上位
- js 窗口操作
- HDU 1561(树形dp)
- eclipse启动项目非常慢
- poj 2455 Secret Milking Machine (网络流)