标签:des style blog http color java os io strong
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2542 Accepted Submission(s): 1238
#include<cstdio> #include<cstdlib> #include<algorithm> #include<cmath> #include<cstring> using namespace std; typedef long long ll; ll xzq; int n,m,i,j,k,l,t,x,y,tl,tt; int a[15][15]; __int64 f[12][12][8193]; int main() { scanf("%d",&tl); for(tt=1;tt<=tl;tt++){ xzq=0; memset(f,0,sizeof(f)); memset(a,0,sizeof(a)); scanf("%d%d",&n,&m); for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ scanf("%d",&a[i][j]); } } f[0][m][0]=1; for(i=0;i<=n;i++){ for(j=1;j<=m;j++){ if(i==0&&j<m)continue; for(k=0;k<=(1<<(m+1))-1;k++)if(f[i][j][k]){ if(j==m){ if(i!=n){ t=k*2; if(t>=(1<<(m+1)))t=t-(1<<(m+1)); t=t-(t&1)-(t&2); if((k&1)==0){ if(a[i+1][1]==0)f[i+1][1][t]+=f[i][j][k]; else{ if(i+1!=n&&m>1)f[i+1][1][t+3]+=f[i][j][k]; } } else{ if(a[i+1][1]!=0){ if(m>1)f[i+1][1][t+2]+=f[i][j][k]; if(i+1!=n)f[i+1][1][t+1]+=f[i][j][k]; } } } } else{ x=1<<j; y=1<<(j+1); t=k; t=t-(t&x)-(t&y); l=k&(x+y); if(l==0){ if(a[i][j+1]==0)f[i][j+1][t]+=f[i][j][k]; else{ if(i!=n&&j+1!=m)f[i][j+1][t+x+y]+=f[i][j][k]; } } if(l==x||l==y){ if(a[i][j+1]!=0){ if(i!=n)f[i][j+1][t+x]+=f[i][j][k]; if(j+1!=m)f[i][j+1][t+y]+=f[i][j][k]; } } if(l==x+y){ if(a[i][j+1]!=0)f[i][j+1][t]+=f[i][j][k]; } } } } } xzq=f[n][m][0]; printf("Case %d: There are %I64d ways to eat the trees.\n",tt,xzq); } }
标签:des style blog http color java os io strong
原文地址:http://www.cnblogs.com/applejxt/p/3931838.html