Merge Words
Time limit5sMemory limit128 MB
Given up to 12 uppercase words, find the shortest string containing all of them as substrings, breaking ties by lexicographic order.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Bit manipulation, String, String matching
- Solved
- No attempts yet
Problem
You are given N words consisting only of uppercase English letters. Print the shortest string that contains every given word as a substring.
Input
The first line contains the number of words N (1 <= N <= 12). Each of the next N lines contains one word consisting only of uppercase English letters. Each word has length at most 50.
Output
Print the answer on the first line. If there are multiple possible answers, print the lexicographically smallest one.