I am currently learning to solve dynamic programming problems, and I found this problem.
Ferry Loading
I am trying recursive approach,but I am finding it hard to determine the ending of recursive branches.
I am saving dp[index][right_length][left_length].
Their values are obtained from the maximum of int p1,p2,p3.
p1=recurse(index+1,right,left) ; // we can move to the next car
p2=1+recurse(index+1,right+arr[index],left); // we take it and add to the right
p3=1+recurse(index+1,right,left+arr[index]); // we take it and add to the left
I am wondering what the base cases might be.Any help can is appreciated.Thanks in advance.
Full text and comments »