Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So you start with a <code>X * Y</code> rectangle. Say the optimal solution involves making a vertical (or horizontal) cut, then you have two new rectangles with dimensions <code>X * Y1</code> and <code>X * Y2</code> with <code>Y1 + Y2 = Y</code>. Since you want to maximize your profit, you need to maximize the profit on these new rectangles (<em>optimal substructure</em>). So your initial recursion goes as follows: <code>f(X, Y) = max(f(X, Y1) + f(X, Y2), f(X1, Y) + f(X2, Y))</code> for all posible values of <code>X1, X2</code> (horizontal cut) and <code>Y1, Y2</code> (vertical cut).</p> <p>Now the question is <em>when do I actually decide to make a product ?</em> You can decide to make a product when one of its dimensions equals one of the dimensions of your current rectangle (why ? Because if this doesn't hold, and the optimal solution includes making this product, then sooner or later you will need to make a vertical (or horizontal) cut and this case is already handled in the initial recursion), so you make the appropriate cut and you have a new rectangle <code>X * Y1</code> (or <code>X1 * Y</code>), depending on the cut you made to obtain the product), in this case the recursion becomes <code>f(X, Y) = cost of product + f(X1, Y)</code>.</p> <p>The solution of the original problem is <code>f(X, Y)</code>. The running time of this dp solution would be <code>O(X * Y * (X + Y + number of available products))</code>: you have <code>X * Y</code> possible rectangles, for each of these you try every possible cut (<code>X + Y</code>) and you try to make one of the available products out of this rectangle.</p> <p>Also, check out this similar problem: <em>Sharing Chocolate</em> from the 2010 ICPC World Finals.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload