#P8865. [NOIP2022] 种花
[NOIP2022] 种花
Description
Xiao C decides to plant a pattern of the letters in his garden, so he wants to know how many planting schemes there are for the letters and respectively. Unfortunately, there are some pits in the garden where flowers cannot be planted, so he hopes you can help solve this problem.
The garden can be viewed as a grid with positions, with rows numbered to from top to bottom, and columns numbered to from left to right. Each position may be a pit or not. Use to indicate that there is a pit at row , column , and use otherwise.
A planting scheme is called shaped if there exist and , satisfying and , such that the segments from columns to on row , from columns to on row , and from rows to on column are all not pits, and flowers are planted only on these positions.
A planting scheme is called shaped if there exist and , satisfying and , such that the segments from columns to on row , from columns to on row , and from rows to on column are all not pits, and flowers are planted only on these positions.
Examples of shaped and shaped planting schemes are shown in the explanation of Sample 1.
Now Xiao C wants to know, given , , and the values indicating whether each position is a pit, how many possible shaped and shaped planting schemes there are, respectively. Since the answer may be very large, you only need to output the result modulo . See the output format section for details.
Input Format
The first line contains two integers , denoting the number of test cases and the test point ID, respectively. If the input is a sample, it is guaranteed that .
Then there are test cases. In each test case:
- The first line contains four integers , where and denote the number of rows and columns of the garden, respectively. The meanings of and are described in the output format section.
- The next lines each contain a string of length consisting only of and . The -th character of the -th string denotes , i.e., whether the cell at row , column in the garden is a pit.
Output Format
Let the numbers of shaped and shaped planting schemes in the garden be and , respectively. For each test case, output one line with two non-negative integers separated by a space, representing and , respectively, where denotes modulo .
1 0
4 3 1 1
001
010
000
000
4 2
Hint
【Explanation of Sample 1】
The four shaped planting schemes are:
**1 **1 **1 **1
*10 *10 *10 *10
**0 *** *00 *00
000 000 **0 ***
Here denotes planting a flower at that position. Note that the two horizontal strokes of do not need to have the same length.
Similarly, the two shaped planting schemes are:
**1 **1
*10 *10
**0 ***
*00 *00
【Sample 2】
See the attachments and .
【Sample 3】
See the attachments and .
【Constraints】
For all test cases, it is guaranteed that , , , and .
| Test point ID | Special property | Score | ||||
|---|---|---|---|---|---|---|
| None | ||||||
| A | ||||||
| B | ||||||
| None | ||||||
Special property A: $\forall 1 \leq i \leq n, 1 \leq j \leq \left\lfloor \frac{m}{3} \right\rfloor$, .
Special property B: $\forall 1 \leq i \leq \left\lfloor \frac{n}{4} \right\rfloor, 1 \leq j \leq m$, .
Translated by ChatGPT 5
京公网安备 11011102002149号