some dp problems

This commit is contained in:
2024-06-14 19:49:10 +02:00
parent 66d059f230
commit b67bf7bbea
21 changed files with 124 additions and 1 deletions

View File

@@ -0,0 +1,23 @@
// Minimizing Coins
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, x;
cin >> n >> x;
vector<int> dp(x + 1, INT_MAX - 5);
dp[0] = 0;
for (int i{}; i < n; i++) {
int c; cin >> c;
for (int j = c; j <= x; j++) {
if (j >= c) {
dp[j] = min(dp[j - c] + 1, dp[j]);
}
}
}
if (dp[x] != INT_MAX - 5) cout << dp[x] << endl;
else cout << -1 << endl;
return 0;
}