#P4558. [JSOI2018] 机器人
[JSOI2018] 机器人
Description
Jiutiao Kelian (pinyin) is a lazy girl. Because she is too lazy to sweep the floor, she bought a robot vacuum cleaner.
Kelian’s home can be abstracted as an grid, with coordinates from to . Every night, Kelian starts the robot at . After being started, the robot follows a preset route and stops when it returns to again.
Due to technical reasons, the robot can only move right (column index plus one) or down (row index plus one). To ensure the robot can return to smoothly, Kelian installed some corridors such that:
- If the robot is currently at , then moving one step to the right takes it to .
- If the robot is currently at , then moving one step down takes it to .
Kelian hopes that, after starting the robot and before it returns to , it passes through every cell exactly once. This way the house gets cleaned without taking too much time. After a simple calculation, she quickly obtained all different plans (two plans are different if and only if the orders in which they visit the cells are different). She then loaded all those plans into the robot.
On this day, Kelian bought some new furniture. After placing the furniture, some cells became obstacles that the robot cannot pass. Under all previously prepared plans, the robot will crash into some obstacle and stop.
For a plan , define as the number of cells the robot passes before it hits an obstacle under that plan. Now Kelian wants to compute the sum of over all different plans.
Input Format
The input contains multiple test cases.
The first line contains an integer denoting the number of test cases.
For each test case, the first line contains two integers , denoting the size of the house.
Then follow lines, each containing a binary string of length . In the -th line, the -th character being '0' means the cell is not an obstacle; otherwise it is an obstacle.
It is guaranteed that is not an obstacle and there is at least one obstacle.
Output Format
For each test case, output a single integer, the answer modulo .
2
2 4
0111
1111
2 4
0010
1000
2
5
Hint
Explanation for Sample 2
When , there are two valid plans:

In the first plan, the robot passes a total of 4 cells before it crashes into the obstacle at .
In the second plan, the robot passes a total of 1 cell before it crashes into the obstacle at .
Therefore, the answer for the second test case is .
Constraints
- Testdata 1 : .
- Testdata 2 : , and all cells except are obstacles.
- Testdata 3 : .
- For all testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号