POJ 3254 状态压缩DP
2013-10-08 21:25
176 查看
我的状态压缩的第一题,忘记取模错了2次。
符合的状态000 001 010 100 101 记得和该行原来状态看是否符合。
符合的状态000 001 010 100 101 记得和该行原来状态看是否符合。
#include<cstdio> #include<iostream> #include<cstring> using namespace std; int dp[13][1<<14],state[1<<14],cur[13]; int m,n,top; const int one_one=100000000; void Init() { int total=1<<n,i; for(i=0;i<total;i++){ if(i&(i<<1)) continue; else state[top++]=i; } } bool fit(int a,int b) { if(a&b) return false; return true; } void Dp() { int i,j,k; for(i=0;i<top;i++){ if(fit(cur[1],state[i])) dp[1][i]=1; } for(i=2;i<=m;i++){ for(j=0;j<top;j++){ if(!fit(cur[i],state[j])) continue; else{ for(k=0;k<top;k++){ if(!fit(cur[i-1],state[k])) continue; if(fit(state[j],state[k])) dp[i][j]=(dp[i][j]+dp[i-1][k])%one_one; } } } } int ans=0; for(i=0;i<top;i++){ ans=(ans+dp[m][i])%one_one; } printf("%d\n",ans); } int main() { int i,j,temp; scanf("%d %d",&m,&n); for(i=1;i<=m;i++){ for(j=1;j<=n;j++){ scanf("%d",&temp); if(temp==0) cur[i]+=1<<(n-j); } } top=0; memset(dp,0,sizeof(dp)); Init(); Dp(); }
相关文章推荐
- [状态压缩DP] POJ 3254
- poj 3254 Corn Fields(状态压缩dp)
- poj 3254 Corn Fields(状态压缩DP)
- POJ 3254 Corn Fields (状态压缩DP)
- POJ 3254 Corn Fields 状态压缩DP
- POJ 3254 状态压缩DP
- POJ 3254 Corn Fields 状态压缩DP (C++/Java)
- poj 3254 corn fields (状态压缩dp~)
- poj-3254-Corn Fields-状态压缩DP
- poj 3254 Corn Fields 状态压缩dp
- Corn Fields POJ - 3254(状态压缩dp入门)
- POJ 3254 Corn Fields (状态压缩DP)
- POJ-3254 Corn Fields 入门级状态压缩DP
- poj 3254 状态压缩dp 放牧~
- POJ 3254 Corn Fields 状态压缩DP (C++/Java)
- poj 3254 Corn Fields ,状态压缩DP
- poj3254 状态压缩dp
- POJ 3254 Corn Fields(状态压缩DP)
- Corn Fields POJ - 3254 状态压缩dp入门
- POJ 3254 Corn Fields——状态压缩dp