Title Link: Hdu 5155 Harry and Magic Box
d p [ i Span style= "Font-family:stixgeneral-regular,serif" > [ j " represents i ? j the number of matrix schemes,d p [ i Span style= "Font-family:stixgeneral-regular,serif" > [ j " fromd P[I?k ][J ?1]in the previous j-1 column, the k behavior is empty, then the rows must have gems in column J.
#include <cstdio> #include <cstring> #include <algorithm>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 &l t;= 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 <=; i++) t[i] = t[i-1] * 2 mod;for (int i = 0; I <=; i++) dp[i][1] = dp[1][i] = 1;f or (int i = 2; I <=; i++) {for (int j = 2; J <=; 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%d", &n, &m) = = 2) {printf ("%d\n", (int) dp[n][m]);} return 0;}
Hdu 5155 Harry and Magic Box (DP)