DEV Community

Discussion on: Solving the Knapsack Problem with Dynamic Programming

Collapse
 
nhthung profile image
Le Nhat Hung • Edited

Great explanations despite small but important mistakes in the write-up. For the museum variant, you handled the case of not choosing the item with:

K(i - 1, w - wi)

whereas it should be:
K(i - 1, w)

because we're not subtracting the item weight from the intermediate weight limit.
However, the code has it right.

Collapse
 
downey profile image
Tim Downey

Thanks for pointing that out! Fixed!