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.

27 lines
597 B

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N];
int n, m;
int f[N][10010];
//x:第几个位置
//m:钱数上限
int dfs(int x, int m) {
if (dp[x][m]) return dp[x][m];
int ans = 0;
if (m == 0) return 1;
if (x == n) return 0;
if (a[x + 1] <= m) ans += dfs(x + 1, m - a[x + 1]); //选择当前位置的菜
ans += dfs(x + 1, m); //不选择当前位置的菜
dp[x][m] = ans;
return ans;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++)cin >> a[i];
cout << dfs(0, m) << endl;
return 0;
}