poj 3254
来源:互联网 发布:链轮设计参数计算软件 编辑:程序博客网 时间:2024/06/07 01:15
<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>
0 0
- POJ 3254
- poj 3254
- POJ 3254
- poj 3254
- poj 3254
- poj 3254
- poj 3254
- poj 3254
- poj-3254
- poj 3254
- poj 3254
- poj 3254
- poj 3254
- POJ 3254
- poj 3254
- poj 3254
- POJ 3254
- [状态压缩DP] Poj 3254, Poj 1185
- 神级代码编辑软件(Sublime Text 3) v3.3114 汉化特别版
- Django中实现文件下载功能
- JavaScript踩坑小计——变量的作用域和类型声明
- java异常机制
- sysconf、pathconf和fpathconf函数
- poj 3254
- Java Iterator
- 利用jquery写无缝循环滑动的轮播图
- Html.ActionLink无法跳转
- ionic 中$ionicView.beforeEnter 事件的一个bug
- Swoole Framework 入门教程(1)
- Android中visibility属性VISIBLE、INVISIBLE、GONE的区别
- 6. ZigZag Conversion
- 转回到Edison上开发