I am trying to go over some notes and examples of dynamic programming, and I have having some difficulty figuring out how it all works. I will post the question, and then what I am having difficulty with:
Given a sequence of points p1= (x1,y1),...,pn=(xn,yn) sorted from left to right (ie, x1 < x2 < ... < xn) and a number k between 1 and n, find a polygonal chain from p1 to pn with k edges that goes from left to right, minimizing the sum of the vertical distances of the points to the chain. Design dynamic programming algorithm that solves the problem in O(n^3) time. Set the subproblems, give all base cases necessary, calculate recursive formula, and write pseudocode for the algorithm. Also a function f(a,b) is defined for us to use in calculating the vertical difference, so I dont have to worry about implementing that. I can just use it as f(a,b)
I believe that the subproblems should be divided as such:
C[i,j] = polygonal chain from p1 to pi with j edges, minimizing the sum of vertical distances.
And then the answer would be: C[n,k]
Base case: C[i,0] = 0
And now I am having some difficulty coming up with the recursive formula. My first question, have I broken the subproblems up correctly? The question gives a hint that makes it seem like I did, but I am not 100% sure. If I am, any hints on how to proceed with deriving the recursive formula?
Thanks for any help guys.