Dynamic Programming: Knapsack - Number of Ways to Make Change
Identify the bug in the following code snippet for counting ways to make change using 1D DP:
def count_ways_bug(coins, amount):
dp = [0] * (amount + 1)
dp[0] = 0
for coin in coins:
for w in range(amount, coin - 1, -1):
dp[w] += dp[w - coin]
return dp[amount]
What is the bug?