#P2167. [SDOI2009] Bill的挑战

    ID: 1146 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dp2009各省省选山东枚举,暴力状态压缩,状压

[SDOI2009] Bill的挑战

Description

Sheng_bill not only has amazing mental arithmetic, but can also easily handle various statistics. In yesterday's contest, you tied with him thanks to your excellent program, which made Sheng_bill extremely displeased. So he challenges you again. This time, you must not lose.

The rules are as follows:

Given NN strings of the same length (composed of lowercase English letters and ?), S1,S2,,SNS_1, S_2, \dots, S_N, count the number of strings TT that match exactly KK of these NN strings. Output the answer modulo 10000031000003.

A string SxS_x (1xN1 \le x \le N) matches TT if the following conditions hold:

  1. Sx=T|S_x| = |T|.
  2. For any 1iSx1 \le i \le |S_x|, either Sx[i]=?S_x[i] = \texttt{?} or Sx[i]=T[i]S_x[i] = T[i].

Here TT contains only lowercase English letters.

Input Format

This problem contains multiple test cases.

The first line contains an integer TT, the number of test cases.

For each test case, the first line contains two integers, NN and KK.

The next NN lines each contain a string SiS_i.

Output Format

For each test case, output a single line with one integer, the answer.

5
3 3
???r???
???????
???????
3 4
???????
?????a?
???????
3 3
???????
?a??j??
????aa?
3 2
a??????
???????
???????
3 2
???????
???a???
????a??
914852
0
0
871234
67018

Hint

Constraints and Conventions:

  • For 30%30\% of the testdata, N5N \le 5, Si20|S_i| \le 20.
  • For 70%70\% of the testdata, N13N \le 13, Si30|S_i| \le 30.
  • For 100%100\% of the testdata, 1T51 \le T \le 5, 1N151 \le N \le 15, 1Si501 \le |S_i| \le 50.

Translated by ChatGPT 5