#P9490. ZHY 的矩阵

    ID: 10152 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP递推O2优化分类讨论

ZHY 的矩阵

Problem Description

In ZHY's memory, there is a 00-11 matrix AA with kk rows and nn columns, which satisfies the following conditions:

  • Each column contains at most one 11.
  • For any two adjacent 11's in the same row, within the rectangle of kk rows between the two columns (including these two columns), there are at least three 11's in total.

Suddenly, ZHY recalled the values of xx positions in the matrix. Please calculate how many ways there are to fill the remaining positions of AA so that AA satisfies the conditions.


Formally, let the value in row ii and column jj be Ai,jA_{i,j}. Then AA satisfies:

  • For all i[1,k],j[1,n]\forall i \in [1,k],\kern{2pt}j \in [1,n], Ai,j{0,1}A_{i,j} \in \{0,1\}.

  • For all i[1,n]\forall i \in [1,n], j=1kAj,i1\displaystyle\sum_{j=1}^{k} A_{j,i}\le 1.

  • For all i,j[1,n],p[1,k]\forall i,j \in [1,n],\kern{2pt}p \in [1,k] and j>ij>i, if $A_{p,i}=A_{p,j}=1,\displaystyle \sum_{x=i}^{j}A_{p,x}=2$, then $\Big(\displaystyle \sum_{x=1}^{k} \sum_{y=i}^{j} A_{x,y}\Big) \ge 3$.

  • For all i[1,x]\forall i\in[1,x], Aai,bi=ciA_{a_{i},b_{i}}=c_{i}.

Since the answer may be very large, you only need to output the result modulo 109+710^{9}+7. Define that two matrices A,AA,A' are different if and only if there exist i[1,k]i\in[1,k], j[1,n]j\in[1,n] such that Ai,jAi,jA_{i,j}\ne A'_{i,j}.

Input Format

The first line contains three integers n,k,xn,k,x.

The next xx lines each contain three integers ai,bi,cia_{i},b_{i},c_{i}.

Output Format

Output one integer in a single line, representing the answer.

3 2 2
1 1 1
2 2 0

2

Hint

Sample Explanation

There are only the following 22 matrices that satisfy the conditions:

{100000}\begin{Bmatrix} 1&0&0\\ 0&0&0 \end{Bmatrix} {100001}\begin{Bmatrix} 1&0&0\\ 0&0&1 \end{Bmatrix}

This problem uses bundled testdata.

Subtaskid\mathrm{Subtask} \kern{2pt} \mathrm{id} nn xx Special Properties Score
00 8\le 8 k=2k=2 1212
11 2×105\le 2 \times 10^{5} 2×105\le 2\times 10^{5} None 2626
22 109\le 10^{9} =0=0 2323
33 2×105\le 2\times 10^{5} ci=1c_{i}=1 1515
44 None 2424

Constraints: for all testdata, 1n1091 \le n \le 10^{9}, 0x2×1050 \le x \le 2\times 10^{5}, 2k1002\le k \le 100. 1aik1 \le a_{i} \le k, 1bin1 \le b_{i} \le n, ci{0,1}c_{i} \in \{0,1\}. It is guaranteed that there do not exist i,j[1,x],iji,j \in [1,x],\kern{2pt}i\neq j such that ai=aj,bi=bja_{i}=a_{j},\kern{2pt}b_{i}=b_{j}.

Translated by ChatGPT 5