Dp. DP[I][J] can indicate that I row J column satisfies the required number of combinations, consider dp[i-1][k] satisfies the condition, then the K column of line I can be arbitrary arrangement (2^K), the remaining J-k column must be 1, so dp[i][j] + = dp[i-1][k]* (2^k) *c (j , K).
1 /*5155*/2#include <cstdio>3#include <cstring>4#include <cstdlib>5 6 #defineMAXN 517 8 Const__int64 MOD = 1e9+7;9 __int64 DP[MAXN][MAXN];Ten __int64 C[MAXN][MAXN]; One __int64 TWO[MAXN]; A - voidinit () { - intI, J, K, TMP; the -two[0] =1; - for(i=1; i<maxn; ++i) { -Two[i] = (two[i-1] <<1); +Two[i]%=MOD; - } + Ac[1][0] = c[1][1] =1; at for(i=2; i<maxn; ++i) { -c[i][0] = C[i][i] =1; - for(j=1; j<i; ++j) { -C[I][J] = c[i-1][J] + c[i-1][j-1]; -C[I][J]%=MOD; - } in } - to for(i=0; i<maxn; ++i) +dp[i][1] = dp[1][i] =1; - the for(i=2; i<maxn; ++i) { * for(j=1; j<maxn; ++j) { $DP[I][J] = dp[i-1][j]* (two[j]-1)%MOD;Panax Notoginseng for(k=1; k<j; ++k) { -DP[I][J] + = dp[i-1][k]*c[j][k]%mod*Two[k]; theDP[I][J]%=MOD; + } A } the } + } - $ intMain () { $ intN, M; - - #ifndef Online_judge theFreopen ("data.in","R", stdin); -Freopen ("Data.out","W", stdout);Wuyi #endif the - init (); Wu while(SCANF ("%d%d", &n, &m)! =EOF) -printf"%i64d\n", Dp[n][m]); About $ return 0; -}
"Hdoj" 5155 Harry and Magic Box