#P7537. [COCI 2016/2017 #4] Rima
[COCI 2016/2017 #4] Rima
Description
Define the length of the longest common suffix of strings as .
When , we say that the two strings rhyme.
Given strings, you need to form a longest possible sequence of strings (the sequence length is the number of strings in it) such that every pair of adjacent strings in the sequence rhymes.
Input Format
The first line contains an integer .
The next lines each contain one string. It is guaranteed that all strings are distinct, consist of lowercase letters, and the total length does not exceed .
Output Format
Output the maximum possible length of the string sequence.
4
honi
toni
oni
ovi
3
5
ask
psk
krafna
sk
k
4
5
pas
kompas
stas
s
nemarime
1
Hint
[Explanation of Sample 2]
The string sequence has the maximum length, which is .
[Explanation of Sample 3]
No two strings rhyme, so any single string can form a sequence by itself. The answer is .
[Constraints]
For of the testdata, .
For of the testdata, .
[Hints and Notes]
This problem is translated from COCI 2016-2017 CONTEST #4 T5 Rima.
The score of this problem follows the original COCI setting, with a full score of .
Translated by ChatGPT 5
京公网安备 11011102002149号