Advertisement
sol4r

Minimum number of coins required to make the total amount

Aug 28th, 2022 (edited)
1,715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. def cointotal(amount,coins):
  2.         dp = [amount+1]*(amount+1)
  3.         dp[0] = 0
  4.         for a in range(1,amount+1):
  5.                 for c in coins:
  6.                         if a-c >=0:
  7.                                 dp[a] = min(dp[a],1+dp[a-c])
  8.         return dp[amount]
  9. amount = 7
  10. coins = [1,3,4,5]
  11. print(cointotal(amount,coins))
  12.  
  13. #Refer video
  14. #https://www.youtube.com/watch?v=H9bfqozjoqs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement