1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <algorithm> #include <cstring> using namespace std; long long has[120][120],n,m,dp[2][1<<15],cur; void (int a,int b){ if(b&(1<<m)) dp[cur][b^(1<<m)]+=dp[cur^1][a]; } int main(){ memset(has,-1,sizeof(has)); while(scanf("%d %d",&n,&m)==2){ if(m>n) swap(m,n); if(has[m][n]!=-1){ printf("%lldn",has[m][n]); continue; } cur=0; memset(dp,0,sizeof(dp)); dp[cur][(1<<m)-1]=1; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){ cur^=1; memset(dp[cur],0,sizeof(dp[cur])); for(int k=0;k<(1<<m);k++){ update(k,k<<1); if(i>1&&!(k&(1<<(m-1)))) update(k,(k<<1)^(1<<m)^1); if(j>1&&!(k&1)) update(k,(k<<1)^2^1); } } has[m][n]=dp[cur][(1<<m)-1]; printf("%lldn",has[m][n]); } return 0; }
|
近期评论