Count monotone right-and-down knight paths from (1,1) to (H,W) on a grid, avoiding up to 10 blocked squares, modulo 10007.
Medium6Dynamic programmingCombinatoricsNo attempts yetTime limit5sMemory limit512 MBChess has a piece called the knight. Instead of moving in a straight line like the other pieces, the knight jumps in an L shape. Precisely, a knight can jump from square (r1,c1) to square (r2,c2) if and only if (r1−r2)2+(c1−c2)2=5.
In this problem one knight travels across a huge chessboard of height H and width W, from the top-left square (1,1) to the bottom-right square (H,W).
Two restrictions apply.
Count the distinct ways the knight can travel from the top-left square to the bottom-right square under these restrictions. The count can grow very large, so print its remainder modulo the prime 10007.
The first line contains one integer N. N test cases follow.
The first line of each test case contains three integers H, W, and R. Each of the next R lines contains two integers r and c, the row number and column number of one rock. Squares (1,1) and (H,W) never hold a rock, and no two rocks share a square.
Limits
For each test case, print one line prefixed by Case #X: , where X is the 1-based case number, followed by the number of ways to reach the goal square modulo 10007.