0-1 knapsack code problem

codeLink : https://ide.codingblocks.com/s/188035
what’s wrong in my code please correct it and specify my errors

in your code dp[i][j] represents the maximum value you can have when there are i elements present and j is the maximum capacity of your knapsack I hope this point is clear to you . Now coming to your approach there are some errors :-

  1. inside your for loop j should iterate from 0 to w instead of 0 to n as j denotes weight
  2. also inside your for loop at every instance of w should be replaced by j

Here, I have corrected your code : https://ide.codingblocks.com/s/188051

In case of any doubt feel free to ask :slight_smile:
If you got the answer mark your doubt as resolved

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.