状压dp
poj3254:裸
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define rep(i,n) for(int i=1;i<=n;i++) #define clr(x,c) memset(x,c,sizeof(x)) const int mod=100000000; int state[1005],dp[20][1005],cnt[20]; int main(){ int n,m; while(scanf("%d%d",&n,&m)==2){ int cur=0;clr(cnt,0);clr(dp,0); for(int i=0;i<(1<<m);i++) if(!(i&(i<<1))) state[++cur]=i; rep(i,n) rep(j,m) { int tmp;scanf("%d",&tmp); if(!tmp) cnt[i]+=(1<<(m-j)); } rep(i,cur) if(!(state[i]&cnt[1]))dp[1][i]=1; rep(i,n){ rep(j,cur){ if(cnt[i]&state[j]) continue; rep(k,cur) { if(cnt[i-1]&state[k]) continue; if(state[k]&state[j]) continue; dp[i][j]=(dp[i][j]+dp[i-1][k])%mod; } } } int ans=0; rep(i,cur) ans=(ans+dp[n][i])%mod; printf("%d\n",ans); } return 0; }