SLIDE 9 7/14/10 ¡ 9 ¡
Choosing ¡c ¡
One ¡way ¡
Pick ¡pentominoes ¡in ¡alphabetical ¡order ¡
¡F ¡I ¡L ¡N ¡P ¡T ¡U ¡V ¡W ¡X ¡Y ¡Z ¡
Not ¡good: ¡F ¡has ¡192 ¡possible ¡places, ¡I ¡then ¡has ¡~32, ¡very ¡
big ¡search ¡space ¡~2x212 ¡ ¡ ¡
Better ¡ ¡ways ¡
Choose ¡lexicographically ¡first ¡uncovered ¡position, ¡
starting ¡with ¡(1,1), ¡search ¡space ¡~107 ¡
Scott ¡realized ¡that ¡X ¡has ¡essentially ¡three ¡possible ¡places ¡
centered ¡at ¡(2,3), ¡(2,4) ¡and ¡(3,3). ¡The ¡rest ¡leads ¡to ¡ symmetrical ¡solutions. ¡Search ¡space ¡~350,000 ¡
Knuth ¡has ¡a ¡more ¡general ¡solution: ¡ ¡pick ¡column ¡ with ¡minimal ¡number ¡of ¡1-‑s ¡
Let’s ¡dance ¡
Represent ¡each ¡1 ¡in ¡A ¡by ¡a ¡node ¡with ¡5 ¡links ¡
L(x), ¡R(x) ¡(left ¡right) ¡ U(x), ¡D(x) ¡(up ¡down) ¡ C(x) ¡column ¡header ¡
Each ¡row ¡is ¡a ¡doubly ¡(L,R) ¡linked ¡circular ¡list ¡ Each ¡column ¡is ¡a ¡doubly ¡linked ¡(U,D) ¡circular ¡list ¡ Each ¡column ¡has ¡a ¡column ¡header ¡node ¡c ¡with ¡ additional ¡name ¡N(c) ¡and ¡size ¡S(c). ¡ ¡ The ¡column ¡headers ¡form ¡a ¡circular ¡row ¡with ¡a ¡header ¡h ¡ Each ¡node ¡points ¡at ¡its ¡column ¡header ¡with ¡link ¡C ¡
Our ¡example ¡
a b c d e f g 1 0 0 1 0 1 1 0 2 1 0 0 1 0 0 1 3 0 1 1 0 0 1 0 4 1 0 0 1 0 0 0 5 0 1 0 0 0 0 1 ¡
h ¡ a ¡2 ¡ b ¡2 ¡ c ¡2 ¡ d ¡2 ¡ e ¡1 ¡ f ¡2 ¡ g ¡2 ¡
Search ¡algorithm ¡DLX ¡
search(int ¡k){ ¡ ¡// ¡search ¡is ¡called ¡with ¡k=0 ¡from ¡outside ¡ ¡if(R[h]=h) ¡print ¡O ¡else ¡{ ¡ ¡// ¡O ¡is ¡the ¡set ¡of ¡currently ¡picked ¡rows ¡ ¡ ¡ ¡choose ¡column ¡c ¡ ¡ ¡ ¡cover ¡column ¡c ¡ ¡// ¡pick ¡element ¡c ¡ ¡ ¡ ¡ ¡for ¡each ¡row ¡r ¡= ¡D[c], ¡D[D[c]]… ¡while ¡r!=c ¡{ ¡ ¡ ¡ ¡ ¡ ¡O[k]=r ¡// ¡pick ¡a ¡row ¡with ¡element ¡c ¡ ¡ ¡ ¡ ¡ ¡for ¡each ¡j ¡= ¡R[r], ¡R[R[r]]… ¡while ¡j!=r ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡cover ¡column ¡C[j] ¡ ¡ ¡ ¡ ¡ ¡// ¡all ¡elements ¡in ¡the ¡row ¡are ¡now ¡covered ¡ ¡ ¡ ¡ ¡ ¡search(k+1) ¡ ¡ ¡ ¡ ¡ ¡for ¡each ¡j ¡= ¡L[r], ¡L[L[r]]… ¡while ¡j!=r ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡uncover ¡column ¡C[j] ¡ ¡// ¡uncover ¡in ¡reverse ¡order ¡ ¡ ¡ ¡ ¡ ¡} ¡ ¡ ¡ ¡uncover ¡column ¡c ¡and ¡return; ¡ } ¡} ¡