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

27 lines
573 B
C++
Raw Permalink 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;
f[0][0] = 1; // 求方案数的base case
for (int i = 1; i <= n; i++) {
int a;
cin >> a; // 最多允许选a个
for (int j = 0; j <= m; j++) {
for (int k = 0; k <= min(a, j); k++)
f[i][j] = (f[i][j] + f[i - 1][j - k]) % mod;
}
}
cout << f[n][m] << endl;
return 0;
}