POJ 3254 Corn Fields (状压DP)
2015-03-29 22:00
267 查看
题意:一个n*m的矩阵,每个格子是0或者1,1表示土壤肥沃可以种植草地,0则不可以。在种草地的格子可以放牛,但边相邻的两个格子不允许同时放牛,问总共有多少种放牛的方法?(不放牛也算一种情况)
思路:就是POJ
1185 炮兵阵地 的弱化版,炮兵那题相当于间隔两行,这里是间隔一行,减少一维坐标就可
思路:就是POJ
1185 炮兵阵地 的弱化版,炮兵那题相当于间隔两行,这里是间隔一行,减少一维坐标就可
//192 KB 32 ms C++ 1221 B #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> using namespace std; const int mod = 100000000; int stnum[15]; int state[15][500]; int dp[15][500]; int n,m; int main() { while(~scanf("%d%d",&n,&m)) { memset(dp,0,sizeof(dp)); memset(stnum,0,sizeof(stnum)); for(int i=1;i<=n;i++) { int g=0; for(int j=0;j<m;j++) { int t; scanf("%d",&t); g += (t==1)? (1<<j):0; } for(int s=0;s<1<<m;s++) { if((s|g)!=g) continue; if((s>>1)&s) continue; stnum[i]++; state[i][stnum[i]]=s; } } for(int i=1;i<=stnum[1];i++) dp[1][i]=1; for(int i=2;i<=n;i++) for(int j=1;j<=stnum[i];j++) for(int k=1;k<=stnum[i-1];k++) { if(state[i][j]&state[i-1][k]) continue; dp[i][j]=(dp[i][j]+dp[i-1][k])%mod; } int ans=0; for(int i=1;i<=stnum ;i++) ans=(ans+dp [i])%mod; printf("%d\n",ans); } return 0; }
相关文章推荐
- POJ2441 Arrange the Bulls(状压DP)
- Poj 1185&Poj 2411 状压dp(from Poj2663)
- poj 1185 炮兵阵地 状压dp
- POJ 1185 炮兵阵地 (状压DP)
- 【DP】 POJ 3311 Hie with the Pie 状压 TSP问题
- POJ 2430 Lazy Cows 状压DP
- poj2441(状压dp)
- POJ 3311 Hie with the Pie (状压DP)
- POJ2288 Islands and Bridges(TSP:状压DP)
- POJ 2411 Mondriaan's Dream (状压DP)
- poj 2663 Tri Tiling--状压dp
- poj2411 Mondriaan's Dream 状压dp
- POJ 2441 Arrange the Bulls(状压DP)
- poj_3254 Corn Fields(状压dp)
- POJ 3311 Hie with the Pie (状压DP)
- POJ 3254 Corn Fields(状压DP)
- POJ--2923--Relocation--状压DP
- POJ - 1185 炮兵阵地 (状压dp)
- poj 2836 Rectangular Covering(状压DP)
- POJ 3254 Corn Fields (状压dp)