#P7716. 「EZEC-10」Covering
「EZEC-10」Covering
Problem Description
You are given an chessboard and pieces of paper of size , numbered from to .
You may choose any number of pieces within , and place them onto the chessboard one by one in increasing order of their numbers. Each piece can be placed either horizontally or vertically.
Note: pieces placed later will cover pieces placed earlier.
Given the number of the piece covering each cell on the final board, find the number of different valid plans, modulo .
Two plans are the same if and only if they choose the same number of pieces, the same piece numbers, and the placement position of every piece is the same.
Input Format
The first line contains an integer , the number of testdata groups.
For each testdata group:
- The first line contains five integers .
- The next lines each contain integers, describing the piece number on each cell in the final board. If a cell is not covered, the number is .
- The testdata guarantees that at least one feasible plan exists.
Output Format
For each testdata group:
- Output one integer per line, the number of plans modulo .
1
2 2 4 2 4
1 2
3 3
2
2
2 2 4 2 3
0 0
2 2
2 2 4 2 2
1 1
3 3
1
1
Hint
[Sample 1 Explanation]
It is not hard to see that you can only take pieces numbered . In this case, there are plans:
, , ;
, , .
[Constraints and Conventions]
This problem uses bundled tests.
- Subtask 1 (5 points): .
- Subtask 2 (10 points): .
- Subtask 3 (15 points): .
- Subtask 4 (20 points): .
- Subtask 5 (50 points): no special restrictions.
For of the testdata, , , .
Translated by ChatGPT 5