Open kunaxar opened 1 year ago
for (int w = 1; w <= capacity; w++) { The loop should start with w = 0 instead of w = 1. This is because you want to consider the case when the knapsack's capacity is 0, which is a valid scenario.
for (int w = 1; w <= capacity; w++) { The loop should start with w = 0 instead of w = 1. This is because you want to consider the case when the knapsack's capacity is 0, which is a valid scenario.