[Codewars] Counting Change Combinations

Counting Change Combinations

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10

#include <vector>
unsigned long long countChange(const unsigned int money, const std::vector<unsigned int>& coins) {
std::vector<unsigned long long> dp(money + 1);
dp[0] = 1;
for(auto& c : coins) {
for(unsigned int i = c; i <= money; i++) dp[i] += dp[i-c];
}
return dp[money];
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2023/04/29/PS/Codewars/counting-change-combinations/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.