Question

In a 0/1 Knapsack problem implemented using dynamic programming, a common mistake is to allow items to be reused, effectively turning it into an unbounded knapsack. Which part of the recurrence relation, if incorrectly formulated, would lead to this bug?

A dp[i][j] = max(dp[i-1][j], dp[i-1][j - weights[i]] + values[i])
B dp[i][j] = max(dp[i-1][j], dp[i][j - weights[i]] + values[i])
C dp[i][j] = dp[i-1][j]
D dp[i][j] = dp[i][j - weights[i]] + values[i]
E dp[i][j] = values[i]
Practice Next

Hey! Ask a query