giving wrong answer for 2 test cases
Knapsack problem code doubt
why is it necessary to initialize by -1 …why wont ‘0’ work?
and will this dp[1000][1000] = {-1} work?
not this will not work.
use memset or loop .
with 0 , we cannot distinguish between visited and unvisisted state (because 0 is also a valid answer)
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.