#P9891. [ICPC 2018 Qingdao R] Repair the Artwork
[ICPC 2018 Qingdao R] Repair the Artwork
题目描述
DreamGrid has a paper strip with grids in a line and he has drawn some beautiful patterns in some grids. Unfortunately, his naughty roommate BaoBao drew some other patterns in some other grids when he wasn't at home. Now DreamGrid has to erase BaoBao's patterns without destroying his own patterns.
Let's number the grids from 1 to from left to right. Each grid either contains DreamGrid's pattern, or contains BaoBao's pattern, or is empty.
Each time, DreamGrid can select two integers and (these two integers can be different each time) such that
- , and
- for all , the -th grid either contains BaoBao's pattern, or is empty,
and change the -th grid to an empty grid for all .
How many ways can DreamGrid change all the grids containing BaoBao's pattern to empty grids by performing the above operation exactly times? As the answer may be large, please print the answer modulo .
Let be a valid erasing sequence (), where indicates that DreamGrid selects integers and in the -th operation. Let be another valid erasing sequence (), where indicates that DreamGrid selects integers and in the -th operation. These two sequences are considered different, if there exists an integer () such that or .
输入格式
There are multiple test cases. The first line of the input contains an integer (), indicating the number of test cases. For each test case:
The first line contains two integers and (, ), indicating the number of grids and the number of times to perform the operation.
The second line contains integers ().
- If , the -th grid is empty.
- If , the -th grid contains DreamGrid's pattern.
- If , the -th grid contains BaoBao's pattern.
It's guaranteed that at most 50 test cases have .
输出格式
For each test case, output one line containing the number of ways modulo .
3
2 2
2 0
3 2
2 1 0
3 1
2 1 0
8
3
1