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 6a1d540 commit 6431d47
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dynamic-programming/coin-combinations-i/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Coin Combinations I

Problem page: <https://cses.fi/problemset/task/1635/>
32 changes: 32 additions & 0 deletions dynamic-programming/coin-combinations-i/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <iostream>

#define MOD (int)1e9 + 7

using namespace std;

int main(){
int n{}, x{};
cin >> n >> x;

int coins[n];
for (auto &c : coins){
cin >> c;
}

int memo[x+1];
memo[0] = 1;

for (int i = 1; i <= x; i++){
memo[i] = 0;
for (auto c : coins){
if (i-c >= 0){
memo[i] += memo[i-c];
memo[i] %= MOD;
}
}
}

cout << memo[x] << "\n";

return 0;
}

0 comments on commit 6431d47

Please sign in to comment.