#P3813. [FJOI2017] 矩阵填数
[FJOI2017] 矩阵填数
Description
Given an matrix, the rows are numbered from top to bottom as , and the columns are numbered from left to right as .
You need to fill each cell in this matrix with a number from .
There are some restrictions when filling the matrix. You are given submatrices of this matrix and the maximum value for each submatrix. Your filling must satisfy that the maximum value of each given submatrix is .
Now, your task is to find how many fillings satisfy the constraints.
Two fillings are different if and only if there exists at least one cell where the numbers differ between the two fillings. Since the answer may be large, you only need to output the result modulo .
Input Format
The first line of the input contains an integer , the number of test cases.
For each test case, the first line contains four integers .
Then follow lines, each describing the maximum value of a submatrix. Each line contains five integers , indicating that the submatrix with top-left corner and bottom-right corner has a maximum value of . , .
Output Format
For each test case, output one line: the number of valid fillings modulo .
2
3 3 2 2
1 1 2 2 2
2 2 3 3 1
4 4 4 4
1 1 2 3 3
2 3 4 4 2
2 1 4 3 2
1 2 3 4 4
28
76475
Hint
For of the testdata, .
For another of the data, .
For of the data, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号