#P4471. [BJWC2018] 词韵
[BJWC2018] 词韵
Description
Adrian likes rhyme in poetry. He thinks two words rhyme if and only if the length of their longest common suffix is at least the length of the longer word minus one. That is, words A and B rhyme if and only if . (Here, is the abbreviation for the longest common suffix.)
Now Adrian has words. He wants to select as many words as possible to form a sequence such that any two adjacent words in the sequence rhyme.
Input Format
The first line contains an integer .
Each of the next lines contains a string consisting of lowercase English letters, representing a word. All words are distinct.
Output Format
Output a single line with one integer, the length of the longest word sequence.
5
ask
psk
k
krafna
sk
4
Hint
[Sample Explanation]
One longest word sequence is ask-psk-sk-k.
[Constraints]
30% of the testdata: , and the sum of word lengths does not exceed .
100% of the testdata: , and the sum of word lengths does not exceed .
Translated by ChatGPT 5
京公网安备 11011102002149号