poj 3254
2016-07-15 10:51
211 查看
<span style="font-size:18px;">//题目网址 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=121145#problem/G</span>
<span style="font-size:18px;"> </span>
<span style="font-size:18px;">#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn=4096,inf=1000000000; int matrix[15][15],r,c,table[maxn],k=0,dp[15][maxn+1]; void gettable() { int i; for(i=0;i<(1<<c);++i) { if((i&(i<<1))==0) table[k++]=i;//按位运算还是加括号不然会错 } } bool is_ok(int x,int r) { int i,tmp=0; for(i=0;i<c;i++) { if(matrix[r][i]) tmp+=(1<<(c-i-1)); } if(x&(~tmp))return false;//按位与写成&&了。。改了好久 return true; } int main() { int i,j,rr,res=0; scanf("%d%d",&r,&c); for(i=0;i<r;i++) for(j=0;j<c;j++) scanf("%d",&matrix[i][j]); gettable(); memset(dp,0,sizeof(dp)); for(i=0;i<k;i++)//初始化 { if(is_ok(table[i],0)) dp[0][table[i]]=1; } for(rr=0;rr<r-1;rr++) { for(i=0;i<k;i++) { if(is_ok(table[i],rr)) { for(j=0;j<k;j++) { if(is_ok(table[j],rr+1) && !(table[i]&table[j])) { dp[rr+1][table[j]]+=dp[rr][table[i]]; } } } } } for(i=0;i<k;i++) { res=(res+dp[r-1][table[i]])%inf; } printf("%d\n",res); return 0; } </span>
相关文章推荐
- POJ 3254 - Corn Fields [状压DP]
- poj 2836
- poj 3254
- POJ 2441
- 2014 西安邀请赛状压DP
- Mega Man’s Missions
- HDU 5713 K个联通块 状压dp枚举子集 (2016百度之星复赛)
- 【2015新手赛网络赛】 1004 Good Subsets
- HDU 5561 【2015合肥现场赛】 Kingdom of Tree
- 关于AC自动机与DP的总结
- nyoj 合并游戏(状态压缩dp)
- HDU 5135 Little Zu Chongzhi's Triangles (2014年广州赛区现场赛I题)
- 【PA2014】【BZOJ3717】Pakowanie
- 【SCOI2007】【BZOJ1072】排列perm
- 【CERC2012】【BZOJ4057】Kingdoms
- 【SDOI2009】【BZOJ1879】Bill的挑战
- 【BZOJ2064】分裂
- 【清华集训2014】【BZOJ3812】主旋律
- Codevs2880 送外卖
- codeforces #302 Remembering Strings (dp)