You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
868 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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;
}