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;