#P1470. [IOI 1996 / USACO2.3] 最长前缀 Longest Prefix
[IOI 1996 / USACO2.3] 最长前缀 Longest Prefix
Description
In biology, the structures of some organisms are represented by sequences of uppercase letters that contain their components. Biologists are interested in breaking long sequences into shorter sequences (i.e., elements).
If the elements in a set can be concatenated (elements may be reused) to form a sequence , then we say that can be decomposed into elements from . Not all elements need to appear (for example, BBC does not appear below). For instance, the sequence ABABACABAAB can be decomposed into elements from the set {A, AB, BA, CA, BBC}.
The first characters of sequence are called the length- prefix of . Design a program that, given a set of elements and an uppercase-letter sequence, lets be the longest prefix of that can be decomposed into elements from the given set , and computes the length of .
Input Format
The input begins with a set consisting of several elements, given as a sequence of space-separated strings. All letters are uppercase, and the data may span multiple lines. The set ends with a line that contains only a single .. There are no duplicate elements in the set.
Then follows the uppercase-letter sequence , given as a string, with a newline after every characters.
Output Format
Output a single line containing one integer: the maximum length of a prefix of that satisfies the condition.
A AB BA CA BBC
.
ABABACABAABC
11
Hint
Constraints
For of the testdata, , , and the length of each element in does not exceed .
Translation from NOCOW.
Translated by ChatGPT 5
京公网安备 11011102002149号