标签:dp
1 1 2 2 2 3
1 7 25HintThere are 7 possible arrangements for the second test case. They are: 11 11 11 10 11 01 10 11 01 11 01 10 10 01 Assume that a grids is ‘1‘ when it contains a jewel otherwise not.
/************************************************************************* > File Name: hdu5155.cpp > Author: ALex > Mail: 405045132@qq.com > Created Time: 2015年01月03日 星期六 21时52分09秒 ************************************************************************/ #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 <= 50; ++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) //前i - 1行亮的列数 { for (int k = 1; k <= m; ++k)//这一行放了k个 { for (int t = 0; j + t <= m; ++t)//这一行亮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] %= mod; } } } } printf("%lld\n", dp[n][m]); } return 0; }
标签:dp
原文地址:http://blog.csdn.net/guard_mine/article/details/42375031