#P1688. 新单词接龙问题
新单词接龙问题
Description
Given a dictionary that contains words, define the dictionary order as the order within this dictionary (i.e., the given list order). Select some words and form a word ladder in dictionary order so that the ladder length is maximized.
Rules for the new word ladder:
- Word transformation: from , adding one letter, deleting one letter, or changing one letter can obtain .
- Dictionary-order chain: are in dictionary order.
Input Format
The first line contains an integer (), the total number of words in the dictionary. The next lines, in dictionary order, contain words, one string per line. Each word consists only of lowercase letters, and its length is between and inclusive.
Output Format
Output a single integer on one line, the maximum possible length of the word ladder.
9
cat
dig
dog
fig
fin
fine
fog
log
wine
5
Hint
Sample explanation:
A word ladder of length is: $\texttt{dig}\to \texttt{fig}\to \texttt{fin}\to \texttt{fine}\to \texttt{wine}$.
Translated by ChatGPT 5
京公网安备 11011102002149号