题意:
有n个无区别的物品,将它们划分成不超过m组,求出划分方法数??
思路:
(1)状态:
dp[i][j]:表示j的i划分数
(2)状态转移方程:
当j >= i时:dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
当j < i时:dp[i][j] = dp[i - 1][j];
代码实现:
void solve()
{
dp[0][0];
for (int i = 0; i <= m; i++) {
for (int j = 0; j <= n; j++) {
if (j>=i)
dp[i][j] = dp[i-1][j] + dp[i][j-1];
else
dp[i][j] = dp[i-1][j];
}
}
printf("%d\n", dp[m][n]);
}