i am getting a very large value as output, please check my code
Not getting output
Hello @shivamgoel150 i don’t think that you have implemented the code in the right way .
the code is very simple that you have to just divide the n by 2,3,4 and you have to make comparison and store in dp the maximum ,
like suppose if the number is 12 then you have to make recursion call for (12/2),(12/3) and (12/4) and take their sum ,and you have to store maximum of( sum,n).
her for your reference i am giving you the correct code link . https://ide.codingblocks.com/s/321697
I hope i have cleared your doubt !
Happy LEarning !!
you approach the problem with top down approach and i am solving this by bottom up can you please explain me what is the problem in my code
@shivamgoel150 even your bottom up approach doesn’t look right to me .
i dont know why you are minimising your answer when in quesiton they are asking you to give the maximum weight.
Anyway,the corrected code for bottom up approach is https://ide.codingblocks.com/s/321736.
But for your knowledge i want you to know that in bottom up approach your code will do 10^9 operations in worst case which will cause TLE.
I hope I’ve cleared your doubt .
Happy Learning !!