#P15060. 过河卒
过河卒
Background
It is recommended to be rated Brown.
Problem Description
Yuki has a chessboard with rows and columns. The row indices are , and the column indices are .
The cell in row and column is denoted by . Each cell can be either white or black, denoted by . If , it is white; if , it is black. It is guaranteed that the outermost ring of the board is white, i.e., is guaranteed.
Yuki plans to place some rooks on the board. For a cell , it is called safe if and only if there exists at least one rook in row or column , and there is no rook on cell .
Yuki has the following requirements for a rook placement:
- All rooks are placed on black cells.
- No two rooks are in the same row or the same column.
- A pawn starts from row of the board and cannot reach row while passing only through safe cells.
The pawn moves as follows: suppose the pawn is currently at . Then it can move to any one of , , , as long as the destination is inside the board.
You need to help Yuki compute the number of placements that satisfy the conditions. Since the answer may be large, output the result modulo .
Input Format
This problem contains multiple test cases.
The first line of input contains two positive integers , representing the number of test cases and the test point ID. The sample satisfies .
For each test case:
- The first line contains two positive integers .
- The next lines describe the board. Line contains a string of length , .
Output Format
For each test case, output one line containing one integer, the answer.
3 0
2 2
11
00
2 2
01
01
3 3
100
000
001
3
3
4
Hint
Explanation of Sample 1
This sample has test cases.
For test case , the valid placements are:
- Place no rooks.
- Place a rook at .
- Place a rook at .
For test case , the valid placements are:
- Place no rooks.
- Place a rook at .
- Place a rook at .
For test case , the valid placements are:
- Place no rooks.
- Place a rook at .
- Place a rook at .
- Place rooks at .
Sample 2
See and in the additional files.
This sample has test cases.
In it, test case satisfies , test case satisfies , , and test case satisfies , .
Sample 3
See and in the additional files.
This sample has test cases. All testdata in this sample satisfies .
In it, test case satisfies , test case satisfies , and test case satisfies .
Sample 4
See and in the additional files.
This sample has test cases.
In it, test case satisfies , test case satisfies , and test case satisfies .
Constraints
For all testdata, it is guaranteed that:
- .
- .
- .
For test points where is odd, it is guaranteed that .
::cute-table{tuack}
| Test Point ID | Special Property | ||
|---|---|---|---|
| No | |||
| Yes | |||
| No | |||
Special Property: for all , it is guaranteed that .
Translated by ChatGPT 5