Tetris
Time limit1sMemory limit128 MB
Count ways to fully tile a 4-by-n board with seven Tetris pieces (long piece has 3 cells), given some cells of the first row already covered, modulo 10^6.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Matrix, Combinatorics, Implementation
- Solved
- No attempts yet
Problem

Building the Panama Canal required 20 million hours of human labor. Meanwhile, in the year 2003 alone, people around the world spent 9 billion hours playing computer Solitaire. Sadly, we do not know how much time humanity has devoted to Tetris — but judging from our own experience, we suspect it is a great deal as well.
You are given a rectangular board that is 4 columns wide and rows tall. The state of every cell in the first row is given. You may use 7 different types of pieces (see the figure), with an unlimited supply of each type. These are the pieces normally used in the game of Tetris. Note, however, that the "long" piece occupies three cells, not four. Pieces may be rotated.
You want to cover the entire board with pieces. Pieces may not overlap one another, may not extend outside the board, and may not cover a cell that is already covered. In how many different ways can the whole board be completely covered?
Input
The first line contains a natural number () — the number of tests.
Each test consists of two lines. The first line contains an integer () — the height of the board. The second line contains 4 characters describing the first row; each character is either * or .. A * denotes a cell that is already covered, and a . denotes a free cell.
Output
For each test, determine the number of different ways to completely cover the board with the available pieces, and print that value modulo , one per line.