please modify the code and tell the error
0-N knapsack dp
Hi @Vibhuti0206
In this question you are required to 2D dp array and then fill it in bottom up approach. I have made those changes in your code kindly have a look. In 2D matrix basically first we have to fill 0th column and 0th row with 0. And then we have to use
if (wt[i-1] <= w)
dp[i][w] = max(val[i-1] + dp[i-1][w-wt[i-1]], dp[i-1][w]);
else
dp[i][w] = dp[i-1][w];
for filling the table.
Here is your corrected code :