Skip to content

Commit

Permalink
Add solution
Browse files Browse the repository at this point in the history
  • Loading branch information
RikuPutkinen committed Sep 15, 2023
1 parent b5de175 commit 6a1d540
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dynamic-programming/minimizing-coins/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Minimizing Coins

Problem page: <https://cses.fi/problemset/task/1634/>
31 changes: 31 additions & 0 deletions dynamic-programming/minimizing-coins/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <iostream>
#include <cmath>

using namespace std;

int main(){
int MAXN = 1e6 + 1;
int n{}, x{};
cin >> n >> x;

int c[n];
int ready[x+1];
ready[0] = 0;

for (int i = 0; i < n; i++){
cin >> c[i];
}

for (int i = 1; i <= x; i++){
ready[i] = MAXN;
for (auto j : c){
if (i-j >= 0){
ready[i] = min(ready[i], ready[i-j] + 1);
}
}
}

cout << ((ready[x] == MAXN) ? -1 : ready[x]) << "\n";

return 0;
}

0 comments on commit 6a1d540

Please sign in to comment.