HDU 1693
最水的插头DP,更改一下状态压缩模板之后顺利AC,没什么好说的。
#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define N 10005 #define L(x) x<<1 #define R(x) x<<1|1 #define M(x,y) (x + y)>>1 #define MOD 1000000007 #define MODD 1000000006 #define inf 0x7fffffff #define llinf 0x7fffffffffffffff #define LL __int64 LL binary[20] = {0,1,1<<1,1<<2,1<<3,1<<4,1<<5,1<<6,1<<7,1<<8,1<<9,1<<10,1<<11,1<<12}; LL s[15][15]; LL dp[15][2100],n,m; void dfs(LL i,LL j,LL cnt,LL x,LL flag) { if(x == m + 1) { dp[i][cnt] += dp[i - 1][j]; return ; } if(s[i][x] == 0) { if(flag == 0 && (j&binary[x]) == 0) dfs(i,j,cnt,x + 1,0); } else if(j&binary[x]) { if(flag) { dfs(i,j,cnt,x + 1,0); } else { if(x != m) dfs(i,j,cnt,x + 1,1); dfs(i,j,cnt + binary[x],x + 1,0); } } else { if(flag) { if(x != m) { dfs(i,j,cnt,x + 1,1); } dfs(i,j,cnt + binary[x],x + 1,0); } else { if(x != m) dfs(i,j,cnt + binary[x],x + 1,1); } } } int main() { LL i,j,k,l,test = 1; LL t; scanf("%I64d",&t); while(t--) { scanf("%I64d%I64d",&n,&m); for(i = 1;i <= n;i++) { for(j = 1;j <= m;j++) { scanf("%I64d",&s[i][j]); } } memset(dp,0,sizeof(dp)); dp[0][0] = 1; for(i = 1;i <= n;i++) { for(j = 0;j < binary[m + 1];j++) { if(dp[i - 1][j] == 0) continue; dfs(i,j,0,1,0); } } printf("Case %I64d: There are %I64d ways to eat the trees.\n",test++,dp[n][0]); } return 0; }