#P9891. [ICPC2018 Qingdao R] Repair the Artwork

    ID: 9281 远端评测题 6000ms 256MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp2018O2优化容斥ICPC青岛

[ICPC2018 Qingdao R] Repair the Artwork

题目描述

DreamGrid has a paper strip with nn 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 nn 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 ll and rr (these two integers can be different each time) such that

  • 1lrn1 \le l \le r \le n, and
  • for all lirl \le i \le r, the ii-th grid either contains BaoBao's pattern, or is empty,

and change the ii-th grid to an empty grid for all lirl \le i \le r.

How many ways can DreamGrid change all the grids containing BaoBao's pattern to empty grids by performing the above operation exactly mm times? As the answer may be large, please print the answer modulo 109+710^9 + 7.

Let {(a1,b1),(a2,b2),(am,bm)}\{(a_1, b_1), (a_2, b_2), \dots (a_m, b_m)\} be a valid erasing sequence (1aibin1 \le a_i \le b_i \le n), where (ai,bi)(a_i, b_i) indicates that DreamGrid selects integers aia_i and bib_i in the ii-th operation. Let {(c1,d1),(c2,d2),,(cm,dm)}\{(c_1, d_1), (c_2, d_2), \dots, (c_m, d_m)\} be another valid erasing sequence (1cidin1 \le c_i \le d_i \le n), where (ci,di)(c_i, d_i) indicates that DreamGrid selects integers cic_i and did_i in the ii-th operation. These two sequences are considered different, if there exists an integer kk (1km1 \le k \le m) such that akcka_k \ne c_k or bkdkb_k \ne d_k.

输入格式

There are multiple test cases. The first line of the input contains an integer TT (1T10001 \le T \le 1000), indicating the number of test cases. For each test case:

The first line contains two integers nn and mm (1n1001 \le n \le 100, 1m1091 \le m \le 10^9), indicating the number of grids and the number of times to perform the operation.

The second line contains nn integers aia_i (ai{0,1,2}a_i \in \{0, 1, 2\}).

  • If ai=0a_i = 0, the ii-th grid is empty.
  • If ai=1a_i = 1, the ii-th grid contains DreamGrid's pattern.
  • If ai=2a_i = 2, the ii-th grid contains BaoBao's pattern.

It's guaranteed that at most 50 test cases have n>50n > 50.

输出格式

For each test case, output one line containing the number of ways modulo 109+710^9 + 7.

题目大意

给定整数 T(1T100)T(1\le T\le100). 对于每组数据 :

给定整数 n,m(n100,m109)n, m(n\le 100, m\le10^9). 接下来给出一个长度为 nn 的数组 aa, 保证 ai{0,1,2}a_i\in \{0, 1, 2\}.

你需要执行下面的操作恰好 mm 次:

  • 指定正整数 l,rnl, r \le n, 满足 iN\forall i\in \mathbf{N}i[l,r]i\in[l, r], 有 ai1a_i \ne 1.
  • 将所有满足 i[l,r]i \in [l, r]aia_i 赋值为 00.

求有多少种不同的操作方式, 使得进行所有 mm 次操作后, i[l,r],ai2\forall i\in[l, r], a_i \ne 2. 由于答案可能很大,请输出答案对 109+710^9 + 7 取模的值.

注意 : 对于每个数据点, 至多有 50 组数据满足 n>50n>50.

Translated by

/user/363302

3
2 2
2 0
3 2
2 1 0
3 1
2 1 0
8
3
1