Following is the code for the rod cutting problem.
We have to cut rod such that we maximise the profit.
Output should be the maximum profit possible
It gives correct answer(22) when implemented recursively.
But when I try to implement with dp it is giving wrong answer(25). Where am I doing mistake?
To reproduce the bug uncomment line number 10 and 19
Help with applying dp recursively on Rod Cutting problem
at line no 12
correct check will be
if(i<length){
NOT if(i<=length){
because length will be i+1
as i start from 0
Modified code
1 Like
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.
plz give your feedback