-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_31.py
More file actions
29 lines (18 loc) · 721 Bytes
/
problem_31.py
File metadata and controls
29 lines (18 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# thank you http://algorithms.tutorialhorizon.com/dynamic-programming-coin-change-problem/
coin_list = [1, 2, 5, 10, 20, 50, 100, 200]
def coin(v, amount):
solution = [[0 for x in range(amount + 1)] for y in range(len(v) + 1)]
if amount == 0:
return 0
for i in range(0, len(v) + 1):
solution[i][0] = 1
for i in range (1, amount + 1):
solution[0][i] = 0
for i in range(1, len(v) + 1):
for j in range(1, amount + 1):
if v[i - 1] <= j:
solution[i][j] = solution[i - 1][j] + solution[i][j - v[i - 1]]
else:
solution[i][j] = solution[i - 1][j]
return solution[len(v)][amount]
print(coin(coin_list, 200))