1857: Catenyms
| Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
|---|---|---|---|---|---|
| 3s | 8192K | 84 | 17 | Standard |
A catenym is a pair of words separated by a period such that the last letter of the first word is the same as the last letter of the second. For example, the following are catenyms:
dog.gopher gopher.rat rat.tiger aloha.aloha arachnid.dogA compound catenym is a sequence of three or more words separated by periods such that each adjacent pair of words forms a catenym. For example,
aloha.aloha.arachnid.dog.gopher.rat.tigerGiven a dictionary of lower case words, you are to find a compound catenym that contains each of the words exactly once. The first line of standard input contains t, the number of test cases. Each test case begins with 3 <= n <= 1000 - the number of words in the dictionary. n distinct dictionary words follow; each word is a string of between 1 and 20 lowercase letters on a line by itself. For each test case, output a line giving the lexicographically least compound catenym that contains each dictionary word exactly once. Output "***" if there is no solution.
Sample Input
2 6 aloha arachnid dog gopher rat tiger 3 oak maple elm
Output for Sample Input
aloha.arachnid.dog.gopher.rat.tiger ***
This problem is used for contest: 171
本文介绍了一种名为Catenyms的问题,该问题是寻找一系列单词,使得每个相邻的单词能够通过最后一个字母连接起来形成一个连续的链条。文章详细解释了问题背景,并提供了一个算法解决方案,包括如何构建图、进行连通性检查以及最终找到满足条件的词链。
529

被折叠的 条评论
为什么被折叠?



