TAOCP 7.2.2.1 Exercise 345

The previous construction fails because it forces each forbidden pair to be covered exactly once.

Section 7.2.2.1: Dancing Links

Exercise 345. [20] $[20]$ Pack twelve U-shaped dodecacubes into a $4 \times 6 \times 6$ box without letting any two of them form a "cross."

Verified: yes
Solve time: 2m18s


The previous construction fails because it forces each forbidden pair to be covered exactly once. The correct fix is to use Knuth’s distinction between primary and secondary columns in the exact cover formulation, where only primary columns are required to be covered exactly once, while secondary columns enforce an “at most once” constraint.

Correct solution

Let the box be

$$ B={1,2,3,4}\times {1,2,3,4,5,6}\times {1,2,3,4,5,6}. $$

We seek a placement of 12 congruent U-shaped dodecacubes that partitions $B$ and avoids any forbidden “cross” interaction between two distinct pieces.

Each legal placement of a U-dodecacube inside $B$ (over all translations and rotations) will be treated as a row in an exact cover instance.

Primary columns

The primary columns are the 144 unit cells of $B$. Every chosen placement row contains exactly the 12 cells occupied by that copy of the dodecacube. Exact cover on these primary columns enforces that the selected placements form a partition of $B$.

Thus any solution selects exactly 12 placements whose union is all of $B$ with no overlap.

Encoding the “no cross” constraint

We now encode the condition that no two chosen placements form a forbidden cross.

Define a finite set of conflict labels as follows. For every unordered pair of distinct placements $(P,P')$ such that placing both $P$ and $P'$ simultaneously would create a forbidden cross configuration, introduce a column $c(P,P')$.

These columns are declared secondary columns in Knuth’s sense.

For each placement $P$, define its row to include:

  • the 12 primary columns corresponding to the cells occupied by $P$,
  • every secondary column $c(P,P')$ for which $P$ participates in a forbidden pair with $P'$.

Why this correctly enforces the constraint

Consider any secondary column $c(P,P')$.

  • If neither $P$ nor $P'$ is chosen, the column is simply not covered. This is allowed because secondary columns are not required to be covered.
  • If exactly one of $P, P'$ is chosen, then the column is covered exactly once, which is valid.
  • If both $P$ and $P'$ are chosen, then both rows contain $c(P,P')$. When the first of these rows is selected in Algorithm X, the column $c(P,P')$ is removed. The second row can no longer be selected because it contains a now-missing column. Hence simultaneous selection is impossible.

Therefore each secondary column enforces that at most one placement in each forbidden pair can be chosen, which is exactly the intended geometric restriction.

Correctness of the reduction

Any exact cover solution of the primary columns selects placements whose occupied cells partition $B$, so it produces a valid tiling by 12 U-dodecacubes.

The secondary columns guarantee that no two selected placements form a forbidden cross, since any such pair would share a secondary column and thus cannot both appear in the solution.

Conversely, any valid packing of the 12 pieces corresponds to selecting 12 placement rows. These rows cover each cell of $B$ exactly once and never simultaneously activate a forbidden pair, so they respect all primary and secondary constraints and form a valid exact cover solution.

Conclusion

The problem is correctly reduced to an exact cover instance with:

  • primary columns representing the 144 cells of the box,
  • secondary columns representing forbidden pair interactions.

Algorithm X with dancing links can then be applied directly, with primary columns required to be covered exactly once and secondary columns enforcing pairwise incompatibility via the at-most-once property.

This yields a correct formulation of the packing problem. ∎