Magical Mystery Knight's Tour: Difference between revisions
imported>Kmk21 Created page with "This problems asks you to generate a knights tour on a chessboard such that the sum of the move numbers on the squares of each row and column are equal with the constraint tha..." |
imported>Kmk21 No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 5: | Line 5: | ||
Aside from that, we know exactly which move numbers are left to be "allocated" to column and row sums. We also know our current row and column sums and the average value required remaining to reach the 260 number. If we run into a situation where the remaining available "move numbers" are greater than the average of any row or column, we can prune the search. | Aside from that, we know exactly which move numbers are left to be "allocated" to column and row sums. We also know our current row and column sums and the average value required remaining to reach the 260 number. If we run into a situation where the remaining available "move numbers" are greater than the average of any row or column, we can prune the search. | ||
These | Note that in order to compare the mask of valid moves quickly, we should encode the 64 positions on the chessboard as bits in a 64 bit integer. This allows constant time comparison, which may be necessary. | ||
These three optimizations should allow us to run fast enough. | |||
[[Category:ICPC Problems]] | [[Category:ICPC Problems]] | ||
Line 12: | Line 14: | ||
[[Category:Implementation Hard]] | [[Category:Implementation Hard]] | ||
[[Category:Brute Force]] | [[Category:Brute Force]] | ||
[[Category:DFS | [[Category:DFS]] |
Latest revision as of 23:35, 6 November 2017
This problems asks you to generate a knights tour on a chessboard such that the sum of the move numbers on the squares of each row and column are equal with the constraint that it matches certain "fixed" squares defined in the input.
While it seems that the search space is large, it turns out to be heavily pruned. We know we need to be able to reach any defined squares, so we can create a mask which tells us which squares are 1-move away, 2-moves away, etc. from any given point. Using this, we can limit our moves to only those that can result in our arriving at whatever the next specific square we need to land on.
Aside from that, we know exactly which move numbers are left to be "allocated" to column and row sums. We also know our current row and column sums and the average value required remaining to reach the 260 number. If we run into a situation where the remaining available "move numbers" are greater than the average of any row or column, we can prune the search.
Note that in order to compare the mask of valid moves quickly, we should encode the 64 positions on the chessboard as bits in a 64 bit integer. This allows constant time comparison, which may be necessary.
These three optimizations should allow us to run fast enough.