Harry and Magic Box
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 131 Accepted Submission (s): 64
Problem Descriptionone Day, Harry got a magical box. The box is made of n*m grids. There is sparking jewel in some grids. But the top and bottom of the box are locked by amazing magic, so Harry can ' t see the inside from the top or bottom. However, four sides of the box is transparent, so Harry can see the inside from the four sides. Seeing from the left of the box, Harry finds each row is shining (it means each row have at least one jewel). And seeing from the front of the box, each column is shining (it means each column have at least one jewel). Harry wants to know how many kinds of jewel ' s distribution is there in the box. And the answer is too large, you should output the answer mod 1000000007.
Inputthere is several test cases.
For each test case,there is integers n and m indicating the size of the box. 0 ≤ n Span id= "mathjax-span-7" class= "Mi" style= "font-family:mathjax_math; Font-style:italic; Padding-left:0.167em ">m ≤ 50 .
Outputfor Each test case, just output one line, contains an integer indicating the answer.
Sample Input
1 12 22 3
Sample Output
1725HintThere is 7 possible arrangements for the second Test case. They are:1111111011011011011101101001assume that a grids was ' 1 ' when it contains a jewel otherwise not.
Sourcebestcoder Round #25
Recommendheyang | We have carefully selected several similar problems for you:5157 5156 5153 5152 5151
At first, think of a complex, think of a three-dimensional dp,dp[i][j][k] means put k pieces, now I row J column is bright
And then it's tragic, and it hasn't been transferred.
DP[I][J] indicates that in the first row, each row is lit, and a total of J columns is lit
Consider line I put K, bright t
Dp[i][j + t] = dp[i-1][j] * c[m-j][t] * C[J][K-T]
/************************************************************************* > File Name:hdu5155.cpp > Author: ALex > Mail: [email protected] > Created time:2015 January 03 Saturday 21:52 09 Seconds ******************************* /#include <map> #include <set> #include <queue> #include <stack> #include <vector> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm>using namespace std;const int mod = 1000000007;long Long Dp[55][55];long long c[55][55];void Combine () {memset (c, 0, sizeof (c)); C[0][0] = 1;for (int i = 1; i <=; ++i) {c[i][0] = 1;for (int j = 1; J <= i; ++j) {if (i = = j) {C[i][j] = 1;} else if (j = = 1) {C[i][j] = i;} ELSE{C[I][J] = C[i-1][j-1] + c[i-1][j]; C[I][J]%= mod;} printf ("%d\n", C[i][j]);}}} int main () {Combine (); int n, M;while (~scanf ("%d%d", &n, &m)) {memset (DP, 0, sizeof (DP));DP [0][0] = 1;for (int i = 1; I <= n; ++i) {for (int j = 0; j <= m; ++j)//previous i-1 row-lit column number {for (int k = 1; k <= m; ++k)//This line Put k {for (int t = 0; j + t <= m; ++t)//This line illuminates T {if (K-t < 0) {continue;} Long Long TMP = dp[i-1][j] * c[m-j][t];tmp%= mod;tmp *= c[j][k-t];tmp%= mod;dp[i][j + t] + = tmp;dp[i][j + t]%= mo D;}}}} printf ("%lld\n", Dp[n][m]);} return 0;}
hdu5155---Harry and Magic Box