Knights
Time limit60sMemory limit256 MB
Count non-attacking knight placements on an M by N board with M up to 4 and N up to 1e9, modulo 1000000009.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Matrix, Bit manipulation
- Solved
- No attempts yet
Problem
You place knights on a chessboard with rows and columns. Each square holds at most one knight.
No two knights on the board may attack each other. A knight attacks the square reached by moving two squares in one direction and then one square perpendicular to that direction. In the picture below, the squares attacked by the knight in the center are marked with X.

Given the size of the board, write a program that counts the ways to place the knights. Placing no knight at all counts as one way.
Input
The first line contains the number of test cases . ()
Each of the next lines contains one test case: two integers and , separated by a space, giving the size of the board. (, )
Output
For each test case, print the number of ways to place the knights modulo 1,000,000,009 on its own line.