Dynamic Programming: Knapsack - Number of Ways to Make Change
Examine the following code snippet for counting ways to make change where each coin can be used unlimited times:
What is the subtle bug in this implementation?
def count_ways(coins, amount):
dp = [0] * (amount + 1)
dp[0] = 1
for coin in coins:
for w in range(amount, coin - 1, -1):
dp[w] += dp[w - coin]
return dp[amount]What is the subtle bug in this implementation?
