luogu#P2031. 脑力达人之分割字串
脑力达人之分割字串
Background
Alright, time for the usual prelude.
Voice-over:
At last, after two rounds of rigorous selection, our open audition has come to an end. Now we enter the round-robin stage. There are four matches in the round-robin, and the top scorers advance to the showdown. If scores are tied, rank by time used; if we still cannot determine the top , truncate.
Welcome to the comprehensive arts-and-knowledge show “Play Happily, Win Easily,” proudly presented by Luogu TV. I am LUWM. Learn programming? Choose Luogu. Many thanks to Luogu Online Judge for its strong support. Now, let’s invite contestants to the stage; the big screen will display the problem.
Problem Description
You are given a string. You may split this string into segments. For example, abcvsdaas can be split as abc|vs|d|aas. You are also given a dictionary. Each segment after splitting must contain at least one word from the dictionary as a substring. What is the maximum number of segments you can obtain?
Input Format
- The first line contains a string.
- The second line contains a positive integer , the number of strings in the dictionary.
- The next lines each contain a string , representing a dictionary string.
Output Format
Output one integer, the maximum number of segments.
asdsd
3
as
sd
ds
2
Hint
Special case: If the original string cannot be split, output .
Constraints: For of the testdata, . For of the testdata, . Here, denote the lengths of string and .
Translated by ChatGPT 5