poj2411 状压dp
#include<cstdio> #include<algorithm> #include<cstring> using namespace std; long long dp[12][1<<11]; bool ins[1<<11]; int main(){ int n,m; while(scanf("%d%d",&n,&m)&&n){ for (int i=0;i<(1<<m);i++){ bool cnt=0,x=0; for (int j=0;j<m;j++){ if((i>>j)&1) cnt|=x,x=0; else x^=1; } ins[i]= cnt|x ? 0 : 1; } dp[0][0]=1; for (int i=1;i<=n;i++){ for (int j=0;j<(1<<m);j++){ dp[i][j]=0; for (int k=0;k<(1<<m);k++){ if((j&k)==0 && ins[j|k]) dp[i][j]+=dp[i-1][k]; } } } printf("%lld\n",dp[n][0]); } return 0; }