Topic Links:
http://acm.hdu.edu.cn/showproblem.php?pid=5155
Test instructions
Give N*m the 01 matrix, and ask that its left view and the front face are all 1 of all cases.
Exercises
N,m not more than 50, so can run O (n^2);
Another dp[i][j] represents the former I row (at least one for each line, because this can be considered only if the column will be empty) in the J column is not all 0, then there is a state transition equation:
Dp[i][k]+=dp[i-1][j]*c[m-j][k-j]*c[j][t] (0<=T<=J)
C[I][J] represents all cases where j is 1 in the I-squares. (combined number, can be recursive offline processing out)
(digression: Originally thought to be like the TSP, want to use the set to represent the State, but in fact it fills in the position discontinuous actually does not have the influence, because it is equivalent to the continuous situation. )
1#include <algorithm>2#include <iostream>3#include <cstdio>4 using namespacestd;5 typedef __int64 LL;6 7 Const intMAXN = -;8 Const intMoD = 1e9 +7;9 Ten intN, M; One LL DP[MAXN][MAXN]; A - LL C[MAXN][MAXN]; - voidGet_c () { the for(inti =0; i < MAXN; i++) { -c[i][0] =1; - for(intj =1; J <= I; J + +) C[i][j] = (C[i-1][J] + c[i-1][j-1]) %MoD; - } + } - + voidinit () { AMemset (DP,0,sizeof(DP)); at } - - intMain () { - Get_c (); - while(SCANF ("%d%d", &n, &m) = =2&&N) { - init (); in for(intj =1; J <= M; J + +) dp[1][J] =C[m][j]; - for(inti =2; I <= N; i++) { to for(intj =1; J <= M; J + +) { + for(intK = J; K <= m; k++) { - for(intt =0; T <= J; t++) { the if(k = = J&&t = =0)Continue; *Dp[i][k] + = dp[i-1][J] * C[m-j][k-j]% mod*c[j][t]%MoD; $DP[I][K]%=MoD;Panax Notoginseng } - } the } + } Aprintf"%lld\n", Dp[n][m]); the } + return 0; -}
HDU 5155 Harry and Magic Box DP