- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem031.cpp
More file actions
Latest commit
23 lines (21 loc) · 544 Bytes
/
Copy pathproblem031.cpp
File metadata and controls
23 lines (21 loc) · 544 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<iostream>
#include<vector>
intwaysToChangeMoney(int amount)
{
int denom[] = { 1, 2, 5, 10, 20, 50, 100, 200 };
int denomLen = sizeof(denom) / sizeof(denom[0]);
std::vector<int> mem(amount + 1);
mem[0] = 1;
for (int i = 0; i < denomLen; ++i) {
for (int j = denom[i]; j <= amount; ++j) {
int difference = j - denom[i];
mem[j] += mem[difference];
}
}
return mem[amount];
}
intmain()
{
std::cout << "Answer: " << waysToChangeMoney(200) << '\n';
return0;
}