here in the code
return *max_element(dp[n],dp[n]+W+1);
//what does the return statement doing ?
here we declare dp as 2D but returning as 1D…how it is possible?
//and also the code is not giving correct output…where is the problem in the code?I have written the code as it is told in the tutorials on dp in the cp course.
AtCoder problem D: Knapsack
-
Why are you using max_element when you don’t understand how it works. Anyway, max_elements, takes the begin and end pointer of the array and returns the max_element value in that range, so passing dp[n] actually means passing &dp[n][0], i.e starting address of nth dp array.
-
You are taking the input wrong
-
if (c[i].wet > W)but should beif (c[i].wet > w)
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.