Poj 3254 Corn Fields
来源:互联网 发布:linux arp incomplete 编辑:程序博客网 时间:2024/06/05 08:28
一个简单的状态压缩DP
按行压缩按列压缩都可以
会状压DP了这个就是水题
#include<cstdio>#include<cstring>using namespace std;#define LL long longconst LL mod = 100000000;const int Log = 13;const int maxn = 1<<Log;LL dp[Log][maxn];int bmap[Log];int map[Log][Log];bool able(int x){ return (x & (x<<1)) == 0;}int main(){int n,m;while(~scanf("%d %d",&n,&m)){for(int i=0;i<n;i++){for(int j=0;j<m;j++){scanf("%d",&map[i][j]);}}for(int i=0;i<n;i++){bmap[i] = 0;for(int j=0;j<m;j++){bmap[i] = bmap[i]*2 + (1-map[i][j]);}}memset(dp,0,sizeof(dp));int len = 1<<m;for(int i=0;i<len;i++){if( (i&bmap[0]) == 0 && able(i)){dp[0][i] = 1;}}for(int i=1;i<n;i++){ for(int j = 0;j<len;j++){ if((j&bmap[i])==0 && able(j)){ for(int bj = 0;bj<len;bj++){ if( (bj&j)==0 && able(bj)) (dp[i][j] += dp[i-1][bj]) %= mod; } }}}LL ans = 0;for(int i=0;i<len;i++){(ans += dp[n-1][i]) %= mod;}printf("%lld\n",ans);}return 0;}
0 0
- poj 3254Corn Fields
- POJ 3254 Corn Fields
- poj 3254 Corn Fields
- POJ 3254 Corn Fields
- poj 3254---Corn Fields
- poj 3254 Corn Fields
- poj 3254 Corn Fields
- POJ 3254 Corn Fields
- (poj)3254 Corn Fields
- poj 3254 Corn Fields
- POJ 3254 Corn Fields
- poj 3254 Corn Fields
- POJ 3254 Corn Fields
- poj 3254 Corn Fields
- POJ 3254 Corn Fields
- POJ 3254 Corn Fields
- poj-3254-Corn Fields
- poj 3254 Corn Fields
- 求最小公倍数和最大公约数
- java项目遇到的 java.security.InvalidKeyException:illegal Key Size 报错解决方案
- 如何从被领导到领导别人
- SharedPreference的使用
- Nodejs学习路线图
- Poj 3254 Corn Fields
- Ubuntu14.04安装tomcat7.0和jdk1.7
- leetcode-48.Rotate Image 解法
- android EventBus 使用
- Double的加减乘除
- linux io 阻塞,非阻塞,同步,异步
- uboot 之uboot.lds分析
- bootm命令中地址参数,内核加载地址以及内核入口地址
- 7、Maven的继承