Files
python/TangDou/CSP-J/AcWingTraining/T7/451_ErWei.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

33 lines
813 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int N = 110, mod = 1000007;
int n, m;
int f[N][N]; // f[i][j]: 使用前i种花,摆出j盆花的方案数
int main() {
cin >> n >> m;
// 初始化:没有花时,摆0盆花有1种方案
f[0][0] = 1; // base 边界
for (int i = 1; i <= n; i++) { // 枚举花种
int a;
cin >> a; // 当前花最多取a盆
// 枚举摆放总数
for (int j = 0; j <= m; j++) {
// 枚举当前花种取k盆
for (int k = 0; k <= min(a, j); k++) {
// 状态转移:当前状态 += 前i-1种花摆j-k盆的方案数
f[i][j] = (f[i][j] + f[i - 1][j - k]) % mod;
}
}
}
cout << f[n][m] << endl;
return 0;
}