this is link to my code. plz tell me where i am going wrong.
Test Case 3 gives wrong answer
I am just using recursion and checking all possibilities of packets that can give me weights equal to w and getting minimum of it.
e.g. for test case
5 5
2 5 1 3 4
initially i have remainingWeight = 5, price = 0 i.e, (5,0)
then run a loop to whole array like (4,2) (3,5) (2,1) (1,3) (0,4)
and then get minimum of all and return it.
@lakshya9410
See if the price[i]=-1, it means that packet is not available, but that packets till i-1 can be used to find the answer because we are only restricted for not using this ith packet.
Also add base cases like when let suppose weight is non zero but i=0 it means that no item is present so we cant make that weight.
I am also attaching my Bottom-up DP code for reference if you face any confusion related to conditions or base case then only see this https://ide.codingblocks.com/s/221897
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.
Hey, can u give me the solution of top down approach i.e, memoization of this problem.