This commit is contained in:
e2hang
2025-09-15 22:16:09 +08:00
parent eea1a643fb
commit e9519e8558
19 changed files with 513 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
vector<int> dp(w + 1, 1e9);
dp[0] = 0;
for (int j = 0; j < n; j++) {
for (int i = a[j]; i <= w; i++) {
dp[i] = min(dp[i], dp[i - a[j]] + 1);
}
}
if (dp[w] == 1e9) cout << -1 << endl; // <20>޽<EFBFBD>
else cout << dp[w] << endl;
return 0;
}