luogu#P12731. 蒙德里安的噩梦
蒙德里安的噩梦
Problem Description
Little Z wants to use dominoes to cover an board. Every cell on the board must be covered, and the dominoes must not overlap. He thinks it looks ugly when the short sides of two dominoes touch, so he does not allow this to happen. Now Little Z has already placed a ring of dominoes along the boundary of the board. Please find the number of ways to cover the remaining area with dominoes. The answer may be very large; you only need to output it modulo .
Input Format
The first line contains three integers . Here denotes the number of dominoes that Little Z has already placed.
The next lines each contain three integers , meaning there is already a domino whose top-left corner is at row , column of the board. If , the domino is placed horizontally; if , it is placed vertically.
Output Format
Output one line with one integer, the answer.
1 4 2
1 1 1
1 3 1
0
5 6 12
1 1 2
1 2 2
1 3 1
1 5 2
1 6 2
3 1 1
3 5 1
4 1 2
4 2 2
4 5 2
4 6 2
5 3 1
2
6 6 14
1 1 2
1 2 2
1 3 1
1 5 2
1 6 2
3 1 1
3 5 1
4 1 1
4 5 1
5 1 2
5 2 2
5 5 2
5 6 2
6 3 1
1
Hint
Sample Explanation
In the first sample, the dominoes placed by Little Z are shown in the figure below:

The short sides of the two placed dominoes touch, which is invalid, so the number of solutions is .
In the second sample, the dominoes placed by Little Z are shown in the figure below:

There are two valid solutions:

In the third sample, the dominoes placed by Little Z are shown in the figure below:

There is only one valid solution:

Constraints and Notes
This problem uses bundled testdata.
For of the testdata, it is guaranteed that , . Each pre-placed domino does not overlap with others and is on the boundary, and every boundary cell is covered by the pre-placed dominoes.
For different subtasks, the constraints are as follows:
subtask1 (5 pts): .
subtask2 (10 pts): .
subtask3 (20 pts): .
subtask4 (15 pts): .
subtask5 (20 pts): .
subtask6 (10 pts): .
subtask7 (20 pts): No special constraints.
Translated by ChatGPT 5