So you start with the rectangle X * Y Let's say the optimal solution involves creating a vertical (or horizontal) section, then you have two new rectangles with dimensions X * Y1 and X * Y2 using Y1 + Y2 = Y Since you want to maximize your profit, you need to maximize profit on these new rectangles (optimal substructure). So, your initial recursion is as follows: f(X, Y) = max(f(X, Y1) + f(X, Y2), f(X1, Y) + f(X2, Y)) for all possible values X1, X2 (horizontal section) and Y1, Y2 (vertical section).
Now the question is, when do I really decide to make a product? You can decide to make a product when one of its sizes is equal to one of the dimensions of your current rectangle (why? Because if this is not done and the optimal solution involves creating this product, then sooner or later you will need to make a vertical (or horizontal) slice, and this case is already being processed in the initial recursion), so you make the corresponding cut, and you have a new rectangle X * Y1 (or X1 * Y ), depending on the cut you made to get the product), in in this case recursion with becomes f(X, Y) = cost of product + f(X1, Y) .
The solution to the original problem f(X, Y) . The running time of this dp solution would be O(X * Y * (X + Y + number of available products)) : you have X * Y possible rectangles, for each of them you can try all possible abbreviations ( X + Y ) , and you are trying to make one of the available products from this rectangle.
Also, check out this similar issue: Chocolate Splitting in the ICPC World 2010 Finals.
jplot source share