#P3041. [USACO12JAN] Video Game G

    ID: 2080 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp2012USACOO2优化AC 自动机

[USACO12JAN] Video Game G

Description

Bessie is playing a game with only three skill keys A, B, C available, and these keys can form nn specific combos. The ii-th combo is represented by a string sis_i.

Bessie will input a string tt of length kk, and each time a combo appears in tt, Bessie scores one point. An occurrence of sis_i in tt means that sis_i is a contiguous substring of tt starting at some position. If sis_i is a contiguous substring starting at multiple positions in tt, it is counted multiple times.

If Bessie inputs exactly kk characters, what is the maximum score she can get?

Input Format

The first line contains two integers, the number of combos nn and the number of characters Bessie inputs kk.

Then nn lines follow, each containing a string sis_i representing a combo.

Output Format

Output a single integer representing the answer.

3 7 
ABA 
CB 
ABACB 

4 

Hint

Sample 1 Explanation.

If Bessie inputs ABACBCB, then ABA appears once, ABACB appears once, and CB appears twice, for a total of 44 points. This can be proven optimal.

Constraints

For all testdata, it is guaranteed that:

  • 1n201 \le n \le 20, 1k1031 \le k \le 10^3.
  • 1si151 \le |s_i| \le 15. Here si|s_i| denotes the length of string sis_i.
  • All strings contain only the uppercase letters A, B, C.

Translated by ChatGPT 5