#P2322. [HNOI2006] 最短母串问题

    ID: 1291 远端评测题 1000ms 32MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>字符串动态规划,dp2006各省省选湖南状态压缩,状压

[HNOI2006] 最短母串问题

Description

Given nn strings (S1,S2,,Sn)(S_1, S_2, \dots, S_n), find the shortest string TT such that all nn strings (S1,S2,,Sn)(S_1, S_2, \dots, S_n) are substrings of TT.

Input Format

The first line contains an integer nn, the number of given strings. The next nn lines each contain a string consisting only of uppercase letters.

Output Format

Output a single line containing the shortest string TT. Among all shortest candidates, if there are multiple strings that satisfy the requirement, output the lexicographically smallest one.

2
ABCD
BCDABC
ABCDABC

Hint

For 100%100\% of the testdata, n12n \leq 12, and the length of each string does not exceed 5050.

Translated by ChatGPT 5