TAOCP 7.2.2.1 Exercise 271
A pentomino tiling of a $6\times 10$ rectangle can be encoded as an exact cover problem in the sense of Algorithm X, with items representing both geometric constraints and piece constraints, and with...
Section 7.2.2.1: Dancing Links
Exercise 271. [20] [20] There are 2339 ways to pack the twelve pentominoes into a $6 \times 10$ box, not counting reflections. What's a good way to find them all, using Algorithm X?
Verified: no
Solve time: 2m09s
Solution
A pentomino tiling of a $6\times 10$ rectangle can be encoded as an exact cover problem in the sense of Algorithm X, with items representing both geometric constraints and piece constraints, and with options representing all admissible placements of pentominoes in the board.
Let the board cells be indexed as a set
$C={(r,c)\mid 1\le r\le 6,\ 1\le c\le 10},$
so $|C|=60$. Let the set of pentomino types be
$P={F,I,L,P,N,T,U,V,W,X,Y,Z},$
so $|P|=12$.
The exact cover items are the disjoint union $C\cup P$. Each solution must select options so that every element of $C$ is covered exactly once and every element of $P$ is used exactly once.
Each option corresponds to a legal placement of a pentomino type $p\in P$ on the $6\times 10$ grid, using one of its admissible orientations (rotations and reflections as appropriate for the counting convention). For each placement, the option contains exactly six items in Knuth’s representation: the pentomino identity item $p$ together with the five cells occupied by that placement. Thus every option has the form
${p}\cup{(r_1,c_1),(r_2,c_2),(r_3,c_3),(r_4,c_4),(r_5,c_5)}.$
Algorithm X applied to this instance constructs a search tree whose nodes correspond to partial selections of such placements, with the invariant that selected options are pairwise disjoint in both cell items and pentomino items.
The full set of options is generated by enumerating, for each $p\in P$, every embedding of each distinct orientation of $p$ into the $6\times 10$ rectangle that stays within bounds. This preprocessing step produces the sparse exact cover matrix implicitly represented in dancing-links form, with one node for each incidence of a pentomino placement covering a cell or using a pentomino type.
To obtain all solutions of the tiling problem up to reflections of the rectangle, symmetry must be eliminated so that each dihedral orbit of solutions contributes exactly one representative. The symmetry group of the $6\times 10$ rectangle has eight elements, generated by horizontal reflection, vertical reflection, and $180^\circ$ rotation.
A direct symmetry-breaking condition can be imposed at the level of options by fixing a canonical anchoring constraint. Introduce a distinguished cell, say $(1,1)$, and restrict the search so that $(1,1)$ is covered by a preselected pentomino type $p_0$ in a fixed orientation and fixed position within the board. Concretely, this is implemented by deleting from the option set all placements that do not place $p_0$ in a specified canonical embedding containing $(1,1)$, and then treating $p_0$ as already selected in the initial partial solution.
This restriction removes all images of any complete tiling under any nontrivial symmetry of the rectangle, since every symmetry of the board moves $(1,1)$ to a different cell unless it is the identity. Consequently, each reflection-equivalence class of solutions contains exactly one solution consistent with the anchoring constraint, so no solution is lost beyond the intended quotienting.
Algorithm X is then executed on the reduced exact cover instance. The recursive covering step selects a column corresponding to a cell or pentomino item, covers it via $\text{cover}(i)$ as in (12), recursively explores all compatible options via (9), and restores structure using $\text{uncover}(i)$ as in (14). Each leaf of the search tree corresponds to a complete selection of 12 disjoint pentomino placements covering all 60 cells.
The correctness of the method follows from the equivalence between solutions of the exact cover instance and tilings of the rectangle, together with the fact that symmetry breaking preserves a unique representative per reflection class while not altering feasibility of any class.
This completes the construction of a procedure that enumerates all $2339$ tilings of the $6\times 10$ rectangle up to reflections using Algorithm X. ∎