fork download
  1. # your code goes here
  2. import copy
  3. CONST_INFINITY = 1000000
  4. def bank(cash, coins):
  5. ways = {0: 0}
  6. for start_sum in range(1, cash + 1):
  7. ways[start_sum] = CONST_INFINITY
  8. variable_coins = copy.copy(coins)
  9. coins_nom = variable_coins.keys()
  10. coins_nom.sort()
  11. for coins_value in coins_nom:
  12. if variable_coins[coins_value] != 0 and start_sum >= coins_value and ways[start_sum - coins_value] + 1 < ways[start_sum]:
  13. ways[start_sum] = ways[start_sum - coins_value] + 1
  14. variable_coins[coins_value] -= 1
  15. return ways[cash]
  16. print bank(16, {1: 3, 2: 7, 7: 4, 10: 1})
Success #stdin #stdout 0.01s 7852KB
stdin
Standard input is empty
stdout
3