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