标签:
hdu1693Eat the Trees
不用分左右插头的DP。关键就是逐格递推。行与行之间的转移看轮廓线发现很happy。
1 int a[13][13]; 2 ll dp[13][13][1<<15]; 3 int main() 4 { 5 freopen("input.txt","r",stdin); 6 freopen("output.txt","w",stdout); 7 int T=read(),cs=0; 8 while(T--) 9 { 10 int n=read(),m=read(); 11 for1(i,n)for1(j,m)a[i][j]=read(); 12 dp[0][m][0]=1; 13 for1(i,n) 14 { 15 for0(j,(1<<m)-1)dp[i][0][j<<1]=dp[i-1][m][j]; 16 for1(j,m) 17 for0(k,(1<<(m+1))-1) 18 { 19 int x=1<<(j-1),y=1<<j; 20 if(a[i][j]) 21 { 22 dp[i][j][k]=dp[i][j-1][k^x^y]; 23 if(((k&x)!=0)^((k&y)!=0))dp[i][j][k]+=dp[i][j-1][k]; 24 }else dp[i][j][k]=(!(k&x)&&!(k&y))*dp[i][j-1][k]; 25 } 26 } 27 printf("Case %d: There are %lld ways to eat the trees.\n",++cs,dp[n][m][0]); 28 } 29 return 0; 30 }
标签:
原文地址:http://www.cnblogs.com/zyfzyf/p/4391771.html