CF638B.Making Genome in Berland
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once.
Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome.
You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string.
伯兰科学家面临一项非常重要的任务——根据若干段较短的DNA片段,复原恐龙的DNA!伯兰恐龙的基因组与我们所熟知的基因组完全不同:它可能包含26种不同的核苷酸类型,且每种类型的核苷酸至多出现一次。若我们将所有核苷酸分别赋予不同的英文字母,则伯兰恐龙的基因组将表示为一个非空的小写英文字母字符串,其中每个字母至多出现一次。
科学家们已获得 n 段基因组片段,每段均表示为所求完整基因组的一个子串(即一段非空的连续核苷酸序列)。
你现在需要解决如下问题:协助科学家复原该恐龙基因组。题目保证输入数据不矛盾,且至少存在一个满足条件的字符串。当科学家得知你是一位优秀的程序员后,他们额外要求你:在所有满足条件的字符串中,选择长度最短的一个。若存在多个长度最短的字符串,则任选其一即可。
输入格式
The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of genome fragments.
Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one.
It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings.
输入的第一行包含一个正整数 n(1 ≤ n ≤ 100)—— 表示基因组片段的数量。
接下来的 n 行,每行描述一个片段。每个片段是一个非空字符串,仅由互不相同的英文小写字母组成。所给片段不一定互不相同。片段之间可以任意重叠,且一个片段可能为另一个片段的子串。
保证存在一个由互不相同字母组成的字符串,使得所有给定的片段均为其子串。
输出格式
In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them.
在输出的单行中,打印包含所有给定片段的最短长度的基因组。基因组中的所有核苷酸必须互不相同。如果存在多个满足条件的字符串,则输出其中长度最短者;若仍存在多个满足条件的字符串,可任选其一输出。
输入输出样例
输入#1
3 bcd ab cdef
输出#1
abcdef
输入#2
4 x y z w
输出#2
xyzw
输入解题思路,AI测评打分。不知道怎么写?