G - Wildcards Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 66

問題文

SS を英小文字のみからなる文字列、TT を英小文字および ? のみからなる文字列とします。
TT に含まれる ? をそれぞれ適切な英小文字 11 つで置き換えることで、TTSS に一致させることができるとき、「 SSTT から作れる」と言います。

例えば、a??d からは abcdaddd を作れますが bcdd を作ることはできません。

英小文字のみからなる NN 個の文字列 S1,S2,,SNS_1, S_2, \ldots, S_N が入力として与えられます。
これらの長さはすべて LL です。すなわち、S1=S2==SN=L|S_1| = |S_2| = \cdots = |S_N| = L です。

文字列 TT として、英小文字および ? からなる長さ LL の文字列であって ? をちょうど KK 個含むものを任意に選びます。
S1,S2,,SNS_1, S_2, \ldots, S_N のうち、TT から作れるものの個数」としてありえる最大値を出力してください。

制約

  • 1N10001 \leq N \leq 1000
  • 1L101 \leq L \leq 10
  • 0KL0 \leq K \leq L
  • N,L,KN, L, K は整数
  • S1,S2,,SNS_1, S_2, \ldots, S_N はそれぞれ英小文字のみからなる長さ LL の文字列
  • S1,S2,,SNS_1, S_2, \ldots, S_N は相異なる。

入力

入力は以下の形式で標準入力から与えられる。

NN LL KK
S1S_1
S2S_2
\vdots
SNS_N

出力

答えを出力せよ。


入力例 1Copy

Copy
5 4 2
aabc
bbaa
abbc
cccc
acba

出力例 1Copy

Copy
3

T=T = a?b? とすると、S1=S_1 = aabc, S3=S_3 = abbc, S5=S_5 = acba33 つを TT から作れます。 このとき「 S1,S2,,SNS_1, S_2, \ldots, S_N のうち、TT から作れるものの個数」は 33 であり、これがあり得る最大値となります。 K=2K = 2 より、TT? をちょうど 22 個含むように選ばれなければならないことに注意してください。


入力例 2Copy

Copy
5 4 4
aabc
bbaa
abbc
cccc
acba

出力例 2Copy

Copy
5

T=T = ???? とすると、S1,S2,S3,S4,S5S_1, S_2, S_3, S_4, S_5 のすべてを作れます。


入力例 3Copy

Copy
5 4 0
aabc
bbaa
abbc
cccc
acba

出力例 3Copy

Copy
1

Score : 66 points

Problem Statement

Let SS be a string consisting of lowercase English letters and TT be a string consisting of lowercase English letters and ?.
SS is said to be obtainable from TT when one can replace each occurrence of ? in TT with some lowercase English letter so that TT equals SS.

For example, abcd and addd are obtainable from a??d, while bcdd is not.

You are given NN strings S1,S2,,SNS_1, S_2, \ldots, S_N consisting of lowercase English letters.
All of these strings have a length of LL: S1=S2==SN=L|S_1| = |S_2| = \cdots = |S_N| = L.

A string TT of length LL consisting of lowercase English letters is arbitrarily chosen so that it contains exactly KK ?s.
Find the maximum possible number of strings among S1,S2,,SNS_1, S_2, \ldots, S_N that are obtainable from TT.

Constraints

  • 1N10001 \leq N \leq 1000
  • 1L101 \leq L \leq 10
  • 0KL0 \leq K \leq L
  • NN, LL, and KK are integers.
  • Each of S1,S2,,SNS_1, S_2, \ldots, S_N is a string of length LL consisting of lowercase English letters.
  • S1,S2,,SNS_1, S_2, \ldots, S_N are distinct.

Input

Input is given from Standard Input in the following format:

NN LL KK
S1S_1
S2S_2
\vdots
SNS_N

Output

Print the answer.


Sample Input 1Copy

Copy
5 4 2
aabc
bbaa
abbc
cccc
acba

Sample Output 1Copy

Copy
3

If we let T=T = a?b?, then S1=S_1 = aabc, S3=S_3 = abbc, and S5=S_5 = acba are obtainable from TT. Here, three of the strings S1,S2,,SNS_1, S_2, \ldots, S_N are obtainable from TT, which is the maximum possible number. Note that K=2K = 2, so TT must be chosen to contain exactly two ?s.


Sample Input 2Copy

Copy
5 4 4
aabc
bbaa
abbc
cccc
acba

Sample Output 2Copy

Copy
5

If we let T=T = ????, all of S1,S2,S3,S4,S5S_1, S_2, S_3, S_4, S_5 are obtainable from TT.


Sample Input 3Copy

Copy
5 4 0
aabc
bbaa
abbc
cccc
acba

Sample Output 3Copy

Copy
1


2025-04-22 (Tue)
10:59:33 +00:00