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;
int n, m;
int f[N][N];
int main() {
//文件输入
freopen("QiaHao_01.in", "r", stdin);
scanf("%d %d", &n, &m);
// 恰好,在有前i种物品可以选择的情况下,只有空间为0有一种方案,就是啥都不选
for (int i = 0; i <= n; i++) f[i][0] = 1;
// 由于下面的代码中,每一行都可以从上一行迁移而来,事实上不用真的循环把第一列全部设置为1,
// 只需把f[0][0]=1,即可完成递推关系建立。
// f[0][0] = 1;
for (int i = 1; i <= n; i++) {
int v;
scanf("%d", &v);
for (int j = 0; j <= m; j++) {
f[i][j] = f[i - 1][j];
if (j >= v) f[i][j] += f[i - 1][j - v];
}
printf("%d\n", f[n][m]);
return 0;