Hdu 5155 Harry And Magic Box (DP)
Dp [I] [j] indicates the number of matrix schemes of I ipvj. dp [I] [j] is transferred from dp [I −k] [j −1, if k behavior is null in the J-1 column before enumeration, these rows must have a gem in column j.
# Include
# Include
# Include using namespace std; typedef long ll; const ll mod = 1000000007; const int maxn = 55; ll c [maxn] [maxn], t [maxn], dp [maxn] [maxn]; void init () {for (int I = 0; I <= 50; I ++) {c [I] [0] = c [I] [I] = 1; for (int j = 1; j <I; j ++) c [I] [j] = (c [I-1] [J-1] + c [I-1] [j]) % mod;} t [0] = 1; for (int I = 1; I <= 50; I ++) t [I] = t [I-1] * 2% mod; for (int I = 0; I <= 50; I ++) dp [I] [1] = dp [1] [I] = 1; for (int I = 2; I <= 50; I ++) {for (int j = 2; j <= 50; j ++) {dp [I] [j] = dp [I] [J-1] * (t [I]-1) % mod; for (int k = 1; k <I; k ++) dp [I] [j] = (dp [I] [j] + c [I] [k] * t [I-k] % mod * dp [I-k] j-1] % mod) % mod ;}}int main () {init (); int n, m; while (scanf (% d, & n, & m) = 2) {printf (% d, (int) dp [n] [m]);} return 0 ;}