Bit sets need no undo
transcript
Your queens code loses layouts. The layout search is a recursion. Four robots should give two. It gives zero. One mark was never cleared.
Mark the column. Marks are shared by every call. Mark both diagonals. Clear all three after the call.
Clear two, and one mark stays. A robot is placed in each row. It blocks cells in later branches. All later branches are affected. Layouts disappear.
Use bit sets instead. Pass the new integer down. The caller keeps the old one. No clean-up is needed at all.
Eleven robots, an empty floor. Pruning removes nearly every branch. The search makes 166,926 calls. All orderings would be 39,916,800.
A cell test reads three bits. Test a cell before every choice. That is one step per cell.
A choice adds one bit. The caller keeps the old set. A mark can never be forgotten. Nothing to undo. Full breakdown in the lecture.