luogu#P9891. [ICPC2018 Qingdao R] Repair the Artwork
[ICPC2018 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 .
题目大意
给定整数 . 对于每组数据 :
给定整数 . 接下来给出一个长度为 的数组 , 保证 .
你需要执行下面的操作恰好 次:
- 指定正整数 , 满足 且 , 有 .
- 将所有满足 的 赋值为 .
求有多少种不同的操作方式, 使得进行所有 次操作后, . 由于答案可能很大,请输出答案对 取模的值.
注意 : 对于每个数据点, 至多有 50 组数据满足 .
Translated by
3
2 2
2 0
3 2
2 1 0
3 1
2 1 0
8
3
1