Allowable Length
===================================


.. code-block:: python

    def find_stacks(rows: List[List[Piece]]) -> List[List[Piece]]:
        """
        Finds the stacks of the pieces.
        
        rows: List of row of pieces ordered from top to bottom.
        return: List of stacks of pieces ordered from top to bottom.
        """
        stacks = []
        for row in rows:
            for piece in row:
                added = False
                for stack in stacks:
                    subpiece = stack[-1]
                    if subpiece is subset piece:
                        stack.append(piece)
                        added = True
                if added == False:
                    new_stack = [piece]
                    stacks.append(new_stack)
        return stacks

.. table::

    +---------------+---------------+---------------+---------------+-------+---------------+---------------+
    | len(1,1)      | len(1,2)      | len(1,3)      | len(1,4)      | ...   | len(1,n-1)    | len(1,n)      |
    +---------------+---------------+---------------+---------------+-------+---------------+---------------+
    | -             | len(2,2)      | len(2,3)      | len(2,4)      | ...   | len(2,n-1)    | len(2,n)      |
    +---------------+---------------+---------------+---------------+-------+---------------+---------------+
    | -             | -             | len(3,3)      | len(3,4)      | ...   | len(3,n-1)    | len(3,n)      |
    +---------------+---------------+---------------+---------------+-------+---------------+---------------+
    | -             | -             | -             | len(4,4)      | ...   | len(4,n-1)    | len(4,n)      |
    +---------------+---------------+---------------+---------------+-------+---------------+---------------+
    | ...           | ...           | ...           | ...           | ...   | ...           | ...           |
    +---------------+---------------+---------------+---------------+-------+---------------+---------------+
    | -             | -             | -             | -             | ...   | len(n-1,n-1)  | len(n-1,n)    |
    +---------------+---------------+---------------+---------------+-------+---------------+---------------+
    | -             | -             | -             | -             | ...   | _             | len(n,n)      |
    +---------------+---------------+---------------+---------------+-------+---------------+---------------+


.. math::

   \begin{align}
   & \text{len}(1,1) = \max\{L_d, L_1 + d\} = \max\{1.4, 1 + 0.3\} = 1.4 \\
   & \text{len}(1,2) = 2 \times \max\{L_d, L_2 + d\} = \max\{1.4, 1.5 + 0.3\} = 2 \times 1.8 \\
   & \text{len}(1,3) = 3 \times \max\{L_d, L_3 + d\} = \max\{1.4, 2 + 0.3\} = 3 \times 2.3 = 6.9 \\
   & \text{len}(2,2) = \text{len}(1,1) + \max\{L_1+L_d , L_2 + d\} \\
   & \quad = 1.4 + \max\{1+1.4, 1.5+0.3\} = 1.4 + 2.4 \\
   & \text{len}(2,3) = \min\{\text{len}(1,1) + 2 \times \max\{L_1+L_d, L_3+d\} , \text{len}(1,2) + \max\{L_2+L_d, L_3+d\}\} \\
   & \quad  = \min\{1.4 + 2 \times \max\{1+1.4, 2+0.3\} ,2 \times 1.8 + \max\{1.5+1.4,2+0.3\}\} \\
   & \quad  = \min\{1.4 + 2 \times 2.4 ,2 \times 1.8 + 2.9\} = 6.2 \\
   & \text{len}(3,3) = \text{len}(2,2)+\max\{L_2+L_d,L_3+d\} \\
   & \quad = 1.4 + 2.4 + \max\{1.5+1.4, 2+0.3\} = 1.4 + 2.4 + 2.9 = 6.7
   \end{align}

.. table:: My Table
   :widths: 20 20 20

   +----------------------------+----------------------------+----------------------------+
   | (:math:`1.4, \varnothing`) | (:math:`3.6, \varnothing`) | (:math:`6.9, \varnothing`) |
   +----------------------------+----------------------------+----------------------------+
   | -                          | (:math:`3.8, 1`)           | (:math:`6.2, 1`)           |
   +----------------------------+----------------------------+----------------------------+
   | -                          | -                          | (:math:`6.7, 2`)           |
   +----------------------------+----------------------------+----------------------------+


    