Files
python/TangDou/AcWing/BeiBao/278_1.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

29 lines
868 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;
const int M = 10010;
int n, m;
int v;
int f[N][M];
int main() {
cin >> n >> m;
for (int i = 0; i <= n; i++) f[i][0] = 1; // base case
for (int i = 1; i <= n; i++) {
cin >> v;
for (int j = 1; j <= m; j++) {
// 从前i-1个物品中选择,装满j这么大的空间,假设方案数是5个
// 那么,在前i个物品中选择,装满j这么大的空间,方案数最少也是5个
// 如果第i个物品,可以选择,那么可能使得最终的选择方案数增加
f[i][j] = f[i - 1][j];
// 增加多少呢?前序依赖是:f[i - 1][j - v]
if (j >= v) f[i][j] += f[i - 1][j - v];
}
}
// 输出结果
printf("%d\n", f[n][m]);
return 0;
}