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.

23 lines
727 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 a[N], f[N][M];
int n, m;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i)cin >> a[i];
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) {
//正好相等,方案数+1
if (j == a[i])f[i][j] = f[i - 1][j] + 1;
//如果大于不选就是原来的方案数选了那么就依赖于j-a[i]这些钱在i-1个物品中的方案数
if (j > a[i]) f[i][j] = f[i - 1][j] + f[i - 1][j - a[i]];
//如果小于,没的选择
if (j < a[i]) f[i][j] = f[i - 1][j];
}
cout << f[n][m];
return 0;
}