2048
Time limit2sMemory limit1024 MB
Count the 16-color h by w grids where no two side-adjacent cells share a color, modulo 1,000,000,007, for h up to 6 and w up to 10^18.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Matrix, Combinatorics
- Solved
- No attempts yet
Problem
The game 2048 is played on a grid with tiles. Pressing an arrow key moves every tile with the same number in that direction and merges them. After each move, a tile with a power of two from to appears at a random empty position. The game ends when the grid is full and no tiles can be merged.
Hyun is a skilled hacker but not a strong 2048 player. Hyun wanted to make a tile in this game. Thinking the grid was too narrow to hold , Hyun used hacking skills to change the width to and the height to and played again. Even so, Hyun failed to make a tile every time.
When Dohoon teased Hyun for not being able to merge two tiles, Hyun tried to argue that there are too many possible ending positions to deal with. However, the width has grown so large that Hyun now finds it hard to count those positions. Compute the number of possible final states of the grid when the game ends, on Hyun's behalf. A final state is one where no two adjacent cells hold the same number and every cell holds one of the 16 possible tiles.
Input
The first line contains the number of queries .
From the second line on, each of the lines contains the grid height and width , separated by a space.
Output
For each query, print the number of possible final states modulo , one per line in order.