#P12152. 【MX-X11-T6】「蓬莱人形 Round 1」催眠术

【MX-X11-T6】「蓬莱人形 Round 1」催眠术

Description

Given n,m,kn, m, k, a length-mm integer sequence aa with values in [1,k][1, k], and an n×(m+1)n \times (m+1) matrix cc.

An integer sequence is defined as good if and only if:

  1. All its values are in [1,k][1, k].
  2. Every length-mm integer sequence with values in [1,k][1, k] is a subsequence of it.

For a good sequence bb of length nn, its value is defined as i=1nci,prei\prod\limits_{i=1}^n c_{i, \text{pre}_i}, where prei\text{pre}_i is the maximum prefix length of aa such that a1preia_{1 \sim \text{pre}_i} is a subsequence of b1ib_{1 \sim i}. If no such prefix exists, prei=0\text{pre}_i = 0.

Find the sum of values of all length-nn good sequences, modulo 109+710^9+7.

Input Format

  • The first line contains three positive integers n,m,kn, m, k.
  • The second line contains mm positive integers a1,,ama_1, \ldots, a_m.
  • The next nn lines each contain m+1m+1 positive integers ci,0,ci,1,,ci,mc_{i,0}, c_{i,1}, \ldots, c_{i,m}.

Output Format

Output a single integer: the sum of values of all good sequences modulo 109+710^9+7.

2 1 2
2
2 3
2 3
15
10 2 5
2 3
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
14400

10 3 3
2 3 3
2 3 1 4
5 2 3 1
5 6 6 6
2 2 3 1
7 6 5 7
2 2 3 1
7 6 5 7
2 2 3 1
7 6 5 7
9 8 1 2

350920080

Hint

Explanation #1

The valid good sequences are (1,2)(1, 2) and (2,1)(2, 1). Their values are 2×3=62 \times 3 = 6 and 3×3=93 \times 3 = 9, respectively. The total sum is 6+9=156 + 9 = 15.

Constraints

This problem uses subtask scoring.

For all test data: 1n,m,k4001 \le n, m, k \le 400, 1aik1 \le a_i \le k, 1ci,j<109+71 \le c_{i,j} < 10^9+7.

Subtask nn \le mm \le kk \le Special Property Points
1 8 None 5
2 400 A 10
3 50 None
4 400 30 8 15
5 400
6 400 B
7 None 30
  • Special Property A: All ci,jc_{i,j} are equal.
  • Special Property B: All aia_i are equal.

Translated by DeepSeek R1