upd
This commit is contained in:
14
algorithms/labs/lab7/code/1.py
Normal file
14
algorithms/labs/lab7/code/1.py
Normal file
@@ -0,0 +1,14 @@
|
||||
def greedy_change(n, coins):
|
||||
result = []
|
||||
for value, count in sorted(coins, key=lambda x: -x[0]):
|
||||
while count > 0 and n >= value:
|
||||
n -= value
|
||||
count -= 1
|
||||
result.append(value)
|
||||
return result if n == 0 else None
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
coins = [(10, 3), (5, 2), (2, 5), (1, 10)]
|
||||
N = 28
|
||||
print(greedy_change(N, coins))
|
||||
Reference in New Issue
Block a user