#P15781. [JAG 2025 Summer Camp #3] Grid Painting
[JAG 2025 Summer Camp #3] Grid Painting
题目描述
There is an grid, where initially every cell is painted white. Let (, ) denote the color of the cell in the -th row from the top and the -th column from the left.
You can paint the grid by repeating the following two operations any number of times, in any order.
Operation 1: This operation may be applied only if the rightmost column of the grid is entirely white.
First, perform a cyclic right shift of the entire grid by one column (i.e., for all , , replace with simultaneously).
Then, choose and paint black.
Operation 2: This operation may be applied only if the bottom row of the grid is entirely white.
First, perform a cyclic downward shift of the entire grid by one row (i.e., for all , , replace with simultaneously).
Then, choose and paint black.
Given the final grid after performing some operations, determine the number of operation sequences that could result in it. Since the answer can be very large, output it modulo .
Two operation sequences are considered different if they have different lengths, or if at any step either the shift direction or the segment painted black differs.
:::align{center}
:::
输入格式
The input consists of multiple test cases.
The first line contains an integer (), representing the number of test cases.
test cases follow. Each test case is given in the following format.
$$\begin{aligned} & H \ W \\ & S_1 \\ & \vdots \\ & S_H \end{aligned} $$For each test case, the first line contains integers () and (), representing the height and width of the grid, respectively.
Each of the following lines contains a string of length , representing the final grid, consisting only of the characters ‘#’ and ‘.’. If the -th character of is ‘#’, then is black, and if it is ‘.’, then is white.
输出格式
Output one line per test case: the number of possible operation sequences modulo .
4
2 2
.#
##
2 3
...
...
3 4
#.#.
.#.#
#.#.
6 5
###..
###..
##.##
##.##
..###
..###
6
1
0
210