sir i know that i am using lots of memory in this logic of mine… but for the learning purpose if i want to know am i implemeting the correct logic ar not and if not correct where am i wrong…
so can you please help me with that
Rod cutting 2d dp approach
@Shobhit_kumar
this should be ur recurrence relation->
cutRod(n) = max(price[i] + cutRod(n-i-1)) for all i in {0, 1 … n-1}
later u can use dp array to memoise it
sir yes i have used the approach you are telling me and got the right anwer from there too but here my dp[i][j] is telling maximum profit i can generate by selling the piece of length j-i and my final anwer would be dp[0][n] what is the flaw in this logic??
effectively u want to store length(j-i) only so linear array for memoisation is sufficient where
dp[i] will tell maximum profit we can make from i length rod.
yes sir that is complety fine but i just wanted to know that if i am going with that approach of mine so that will only give MLE and TLE or is the logic also wrong?? that’s my main concern…please elaborate on this
pls share pure recursive code(no dp) with me.
i will check whether it will work or not
yes that worked thanks sir
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.