#P3041. [USACO12JAN] Video Game G
[USACO12JAN] Video Game G
Description
Bessie is playing a game with only three skill keys A, B, C available, and these keys can form specific combos. The -th combo is represented by a string .
Bessie will input a string of length , and each time a combo appears in , Bessie scores one point. An occurrence of in means that is a contiguous substring of starting at some position. If is a contiguous substring starting at multiple positions in , it is counted multiple times.
If Bessie inputs exactly characters, what is the maximum score she can get?
Input Format
The first line contains two integers, the number of combos and the number of characters Bessie inputs .
Then lines follow, each containing a string 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 points. This can be proven optimal.
Constraints
For all testdata, it is guaranteed that:
- , .
- . Here denotes the length of string .
- All strings contain only the uppercase letters
A,B,C.
Translated by ChatGPT 5
京公网安备 11011102002149号