Files
2025-09-15 22:16:09 +08:00

36 lines
633 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
int main(){
int n, m;
cin >> n >> m;
vector<int> arr(n);
vector<int> dp(m + 1, 0);
unordered_map<int, int> mp;
for(int i = 0; i < n; i++){
cin >> arr[i];
mp[i]++;
}
dp[0] = 1;
//dp[i] += dp[i - arr[j]]
/* 0/1背包必须得j在外层不依赖前面的d[i]
for(int i = 1; i <= m; i++){
for(int j = 0; j < n; j++){
if(i - arr[j] >= 0) {
dp[i] += dp[i - arr[j]];
}
}
}*/
//不重复利用元素
for(int j = 0; j < n; j++){
for(int i = m; i >= arr[j]; i--){
dp[i] += dp[i - arr[j]];
}
}
cout << dp[m] << endl;
return 0;
}