1 / 13

d036: Maximum Empress Problem

d036: Maximum Empress Problem. Po-Lung Chen Team Dont Block Me, National Taiwan University March 26, 2010. N -Queen Problem. How many ways to place Queens on an chessboard so that no Queens attack others? A Queen can attack in 8-directions on the board.

bobby
Download Presentation

d036: Maximum Empress Problem

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. d036: Maximum Empress Problem Po-Lung Chen Team Dont Block Me, National Taiwan University March 26, 2010

  2. N-Queen Problem • How many ways to place Queens on an chessboard so that no Queens attackothers? • A Queen can attack in 8-directions on the board.

  3. Problem Description (1/2) • An Empress split herself into four Queens at rotation positions.

  4. Problem Description (2/2) • Let be the maximum number of Empress that can be placed on a chessboard such that none of the Queens split by Empresses can attack. • How many ways to place Empresses on a chessboard “peacefully”?

  5. Observation • If is odd, then we must place an Empress at center. • For any solution, if we split the Empresses into Queens, then rotate the chessboard by 90, 180 or 270 degrees remain the same status on the chessboard. • Consider the Upper-Left region only. • Run a “Depth First Search” on this region.

  6. Simple DFS structure • DFS(row, Now_Empress, Board_Status) • If(row==[n/2]) • If(Now_Empress > Max_Empresses) • Max_Empresses = Now_Empress; • AnswerCount = 0; • If(Now_Empress == Max_Empresses) • AnswerCount++; • Else • DFS(row+1, Now_Empress, Board_Status) • Find a safe place on this row, and modify Board_Status. • DFS(row+1, Now_Empress+1, Modified_Board_Status) The answer is .

  7. Chessboard Status • How do we check whether a place is safe or not? • We can use four arrays of bits to record: • : rows. • : columns. • : diagonal directions. • : off-diagonal directions. Check and Update costs only 4*4 per Empress.

  8. Speeding Up • Even we can do per check and update the status, and only search the upper-left corner, the searching time for is still too long. • Trying to cut off some branches that we don’t need. • Use some estimation, and reflection properties!

  9. Speeding Up – 1 • If it is impossible to reach Max_Empresses, cut it off. • DFS(row, Now_Empress, Board_Status) • If([n/2]-row + Now_Empress < Max_Empresses) • Return; • If(row==[n/2]) • If(Now_Empress > Max_Empresses) • Max_Empresses = Now_Empress; • AnswerCount = 0; • If(Now_Empress == Max_Empresses) • AnswerCount++; • Else • DFS(row+1, Now_Empress, Board_Status) • Find a safe place on this row, and modify Board_Status. • DFS(row+1, Now_Empress+1, Modified_Board_Status)

  10. Speeding Up – 2 • If this is a possible solution with a Queen in the first row of R, then its mirror is another solution. • So, if we find such one, we can count as two. • No need to consider a Queen at first column! R R R R R R R R R R R R

  11. Speeding Up – 3 • Using Dancing Links (DLX) to maintain a sequence (linked list) of places that can still put Empresses in. • Not easy to implement, be careful handling pointers. • This speeds up when the recursion get deeper. • This speeds up if you implement it well  • More information please go to: • http://en.wikipedia.org/wiki/Dancing_Links

  12. By the way… • A Rotational N-Queen Problem, is to find how many N-Queen solutions is invariant under rotation. • The Empress Problem is exactly the same with rotational N-Queen Problem when N is in the form of or . • We can find the sequence of solutions to rotational N-Queen Problem on Web “Integer Sequence”. • See: http://www.research.att.com/njas/sequences/A033148

  13. Finally… Thanks for your attention!

More Related