#P1026. [NOIP 2001 提高组] 统计单词个数
[NOIP 2001 提高组] 统计单词个数
Description
You are given a string of lowercase English letters with length at most (the string is provided as letters per line, and each line has exactly letters). You must split this string into contiguous parts so that the total number of words contained in all parts is maximized.
Words in a part may partially overlap. After selecting one word, its first letter cannot be used again. For example, the string this can contain both this and is, but if this is selected, then th cannot be included.
The set of words comes from a given dictionary of at most words.
Output the maximum count.
Input Format
The input consists of multiple test cases. For each test case:
- The first line contains two positive integers . Here is the number of lines of the string, and is the number of parts to split into.
- The next lines each contain exactly characters.
- The next line contains a positive integer , the number of dictionary words.
- The next lines each contain one word.
Output Format
For each test case, output one integer: the corresponding result.
1 3
thisisabookyouareaoh
4
is
a
ok
sab
7
Hint
- Constraints: For of the testdata, , .
- Sample explanation: A valid partition is
this/isabookyoua/reaoh. - Source: NOIP 2001 Senior, Problem 3.
Translated by ChatGPT 5
京公网安备 11011102002149号