Question: Python DP Algorithm Question: I wrote this DP function fo find the least amount of coins needed to make change for a certain amount of

Python DP Algorithm Question: I wrote this DP function fo find the least amount of coins needed to make change for a certain amount of money using given denominations. I finally got it working IRL (not just on my whiteboard) by looking at a couple other people's examples and seeing that their array (what I call results and coinsUsed) is not just [0], but [0] * (change + 1) .... Once I changed that, it finally worked. This is my first quarter using python for a class.. so maybe it's a python thing. I'm just wondering WHY results and coinsUsed needs to be [0] * (change + 1)? I want to understand. Thank you. Python DP Algorithm Question: I wrote this DP function fo find the

## A Dynamic Programming function ## to find the least amount of # coins required to make change for ## a certain amount of money using 6 ##given denominations 8 def makeChange(coins, change): results [0] * (change + 1) coinsUsed [0] (change 1) quantity - [0] len(coins) c change 10 12 13 14 15 16 17 18 19 20 21 for subproblem in range(change 1): needed subproblem current 1 for coin in coins: if coin subproblem: if results [subproblem coin] 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!