-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsolution.py
51 lines (41 loc) · 1.12 KB
/
solution.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import copy
def solution(amount, money_limits, result=None, current_note=None):
moneyTypes = list(money_limits.keys())
moneyTypes.sort(reverse=True)
if not result:
result = {}
if current_note:
if money_limits[current_note] > 0:
amount -= current_note
money_limits[current_note] -= 1
if current_note not in result:
result[current_note] = 1
else:
result[current_note] += 1
else:
return
if amount < 0:
return
if amount == 0:
yield result
tmp_amount = amount
max_note_i = 0 if not current_note else moneyTypes.index(current_note)
for note in moneyTypes[max_note_i:]:
yield from solution(
tmp_amount,
copy.deepcopy(money_limits),
copy.deepcopy(result),
note
)
if __name__ == '__main__':
amount = 12120
money_limits = {
5000: 10,
1000: 10,
500: 10,
100: 10,
50: 10,
30: 10
}
res = solution(amount, money_limits)
print(next(res))