It sounds like you should step away from this particular problem, and go take the time to study Dynamic Programming. This kind of study will pay off incredibly. Unfortunately, there are no quick tricks to learning algorithm design at a fundamental level. The way to do it is to find a good book, for example Introduction to Algorithms (CLRS) by Cormen et al., and then carefully work through the book and solve problems. For example, Dynamic Programming is covered in chapter 15 of CLRS. Fortunately for you, MIT OCW offers two excellent courses, the introductory 6.006, and the more advanced 6.046, which go very well with this book. Depending on your tastes, you may like the 2005 offering for 6.046, which was taught by Dr. Leiserson, one of the authors.
If you study the material, you will learn that generally, the first step in a DP problem is to characterize the structure of an optimal solution. Then you define the value of the solution using a recurrence relation. This is done away from a computer, with pencil and paper. Those two steps can be non-trivial. However, once you are done, you have a provably correct formulation, and writing the algorithm for a computer is usually remarkably simple. What is the recurrence relation for your problem here?