The Twin Tower
Time limit1sMemory limit256 MB
Count perfect matchings of a 3x3xN grid graph where each of the 9N rooms pairs with an adjacent room, modulo 10007.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Bit manipulation, Matrix, Combinatorics
- Solved
- No attempts yet
Problem
In recent years so many twins have enrolled at Leiden University that housing them has become a big problem. To accommodate everyone, the university plans to build a skyscraper of floors, with 9 rooms on each floor laid out in a square. Everyone must be able to get a room next to, directly above, or directly below their twin. More precisely, the two rooms of a twin must either lie on opposite sides of a common wall, or the floor of one room must be the ceiling of the other. For privacy, students never share a room.
Count all ways to pair up the rooms so that no room is left unpaired, modulo .
Input
The first line contains a single integer : the number of test cases. Each test case is a single line containing one integer with .
Output
For each test case, output on its own line the number of valid pairings, taken modulo .