Mixing Strings
Practice
4.4 (13 votes)
Algorithms
Approved
Brute Force search
Data structures
Easy
Implementation
Open
Problem
70% Success 9071 Attempts 20 Points 5s Time Limit 256MB Memory 1024 KB Max Code

Heisenberg is very fond of mixing various strings together. But he has storage problem. He wants that his strings use as less space as possible.

He has N strings right now. He wants to store them together. To reduce space he can use this property of mixing two strings:

Suppose he has string A="abcdef" and B="cdefghi". He can mix them to form "abcdefghi".

So, two strings can be mixed if some substring at the end of A is also at the starting of B which are mixed together.

Given the list of strings he has right now, print the minimum final characters he can get if he can mix any number of times, any of the given strings or the intermediate strings.

Input:

First line contains N, the number of strings. Next N line contains, one string per line.

Output:

Print in one line the minimum final characters he can get if he can mix any number of times, any of the given strings or the intermediate strings.

Constraints:

\(1 \le N \le 8\)

\(1\le Length of each string \le 15\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
19 votes
Tags:
Basic ProgrammingBasics of ImplementationEasyImplementation
Points:20
9 votes
Tags:
Hash functionAd-HocImplementationHash tableOpenApprovedEasy
Points:20
26 votes
Tags:
AlgorithmsEasy