0-1 knapsack problem

i made a code for this problem but it is not working as
it is supposed to work …please help me to solve it out or upload editorials

rep(j,i,n,1){
if(c >= s[j])
best=max(best,v[j]+fun(j+1,c-s[j]));
else
continue;
}
return best;
}

Can you explain the logic behind this.
BTW you have not declared j in the function.

There, are two ways of solving this problem:

  1. Recursively
  2. using DP approach

Try to solve it yourself.
if you still face problems, feel free to ask.

I am marking this doubt as resolved as you have not replied to this thread for 5 days.
In case, you still have some doubts regarding the same problem then you can reopen this doubt.

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.