Count right-and-down knight paths from (1,1) to (H,W) on a board up to 1e8 wide, avoiding at most 10 rocks, modulo 10007.
Medium7Dynamic programmingCombinatoricsMathImplementationNo attempts yetTime limit5sMemory limit512 MBChess has a piece called the knight. It does not move in a straight line like the other pieces, it jumps in an L shape. Precisely, a knight jumps from square (r1,c1) to square (r2,c2) if and only if (r1−r2)2+(c1−c2)2=5.
In this problem one knight has to cross a gigantic board of height H and width W, from the top left square (1,1) to the bottom right square (H,W).
The rules are these.
Count the distinct ways for the knight to go from (1,1) to (H,W). Two ways are distinct when the sequence of squares the knight lands on differs. The count gets huge, so print its remainder modulo the prime 10007.
The first line contains a single integer N, the number of test cases. 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 the column number of one rock. Neither (1,1) nor (H,W) holds a rock, and no two rocks share a square.
Limits
For each test case, print one line holding Case #X: followed by the number of ways to reach the goal square, taken modulo 10007. X is the 1 based test case number.