1. The Problem
Goal
Place 4 Queens on a \(4 \times 4\) chessboard such that no queen attacks another.
No two queens can share the same:
- Row
- Column
- Diagonal
Symmetry Insight: We only need to consider placing the first queen in the first two squares of the top row. The other two are symmetric reflections.
2. DP Formulation
We can formulate this as finding a path in a graph.
- • Root Node (s): Empty board.
- • Transitions: Placing a queen in the next row in a safe square.
- • Terminal Nodes: Either a full solution (4 queens) or a dead-end (cannot place next queen).
- • Cost: 0 for valid moves. 1 for arcs to artificial terminal node from dead-ends.
3. Complexity
The N-Queens Explosion
For \(N=4\), it's easy. But as \(N\) grows, the state space explodes.
For large \(N\), exact DP is impossible. We need Rollout or other search methods.