首页 > 代码库 > hdu 5155 Harry And Magic Box(DP)
hdu 5155 Harry And Magic Box(DP)
题目链接:hdu 5155 Harry And Magic Box
dp[i][j]表示i?j的矩阵方案数,dp[i][j]从dp[i?k][j?1]中转移,枚举前面j-1列中k行为空,那么这些行在第j列一定有宝石。
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long 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%d", &n, &m) == 2) { printf("%d\n", (int)dp[n][m]); } return 0; }
hdu 5155 Harry And Magic Box(DP)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。