Pressure DP.
#include <cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespacestd;inth,w;Long Longdp[ the][(2<< A)+Ten];BOOLflag[(2<< A)+Ten],c[(2<< One)+Ten];intb[ the];voidDfsintp) { if(p==V) { intst=0; for(intI=0; i<w;i++) st=st+c[i]*B[i]; FLAG[ST]=1;return; } if(c[p]==1) DFS (p+1); Else{ if(p+1<W) {c[p]=1; c[p+1]=1;d FS (p+1); c[p]=0; c[p+1]=0;} DFS (P+1); }}intMain () {b[0]=1; for(intI=1; i<= One; i++) b[i]=2*b[i-1]; while(~SCANF ("%d%d",&h,&W)) {if(h==0&&w==0) Break; DFS (0); Memset (DP,0,sizeofDP); for(intI=0; I<= (1<<W)-1; i++) dp[0][i]=Flag[i]; for(intI=1; i) { for(intj=0; J<= (1<<W)-1; j + +) { if(dp[i-1][j]==0)Continue; intst=j^ ((1<<W)-1); for(intk=0; K<= (1<<W)-1; k++) { if((flag[k]==0)|| ((st&k)! =0))Continue; Dp[i][st|k]+=dp[i-1][j]; }}} printf ("%lld\n", dp[h-1][(1<<W)-1]); } return 0;}
HDU 1400 Mondriaan ' s Dream