[信息与未来 2014] 简单单词接龙

Luogu
IDLGB4132
Time1000ms
Memory512MB
Difficulty
搜索图论2014江苏信息与未来
有 $n$ 个单词,每个单词由 $2$ 个小写字母组成,并约定第 $1$ 个单词为龙头。接龙的方法为:前一单词的第 $2$ 个字母和后一个单词的第 $1$ 个字母相同。**一个单词只能用一次。** 程序要求给出各个单词后,求出最长龙的长度。 ## Input 第一行一个整数,表示 $n$。 接下来 $n$ 行,每行有 $2$ 个小写字母,表示一个单词 $s_i$(单词字母间无空格)。 ## Output 一行一个整数,表示最长龙的长度。 [samples] ## Background 本题是 NPC 问题,没有有道理的做法,因此不处理一切数据问题,仅供参考。 本题应该可以以任意单词作为龙头。 ## Note ### 样例 $\textbf 1$ 解释 可以接龙的方法有: - $\tt aa-ac-cd$,长度为 3; - $\tt aa-ab-bh-hk$,长度为 4。 ### 数据范围 $1\le n\le50$。
Samples
Input #1
7
aa
ac
ab
ef
bh
hk
cd
Output #1
4
Input #2
8
gd
bd
ea
ab
fd
be
df
be
Output #2
6
API Response (JSON)
{
  "problem": {
    "name": "[信息与未来 2014] 简单单词接龙",
    "description": {
      "content": "有 $n$ 个单词,每个单词由 $2$ 个小写字母组成,并约定第 $1$ 个单词为龙头。接龙的方法为:前一单词的第 $2$ 个字母和后一个单词的第 $1$ 个字母相同。**一个单词只能用一次。** 程序要求给出各个单词后,求出最长龙的长度。",
      "description_type": "Markdown"
    },
    "platform": "Luogu",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 524288
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "LGB4132"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "有 $n$ 个单词,每个单词由 $2$ 个小写字母组成,并约定第 $1$ 个单词为龙头。接龙的方法为:前一单词的第 $2$ 个字母和后一个单词的第 $1$ 个字母相同。**一个单词只能用一次。**\n\n程序要求给出各个单词后,求出最长龙的长度。\n\n## Input\n\n第一行一个整数,表示 $n$。\n\n接下来 $n$ 行,每行有 $2$ 个小写字母,表示一个单词 $s_i$(单词字母间无空格)。\n\n#...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments