时间限制:1000ms
单点时限:1000ms
内存限制:256MB
Lara Croft, the fiercely independent daughter of a missing adventurer, must push herself beyond her limits when she discovers the island where her father disappeared. In this mysterious island, Lara finds a tomb with a very heavy door. To open the door, Lara must input the password at the stone keyboard on the door. But what is the password? After reading the research notes written in her father's notebook, Lara finds out that the key is on the statue beside the door.
The statue is wearing many arm rings on which some letters are carved. So there is a string on each ring. Because the letters are carved on a circle and the spaces between any adjacent letters are all equal, any letter can be the starting letter of the string. The longest common subsequence (let's call it "LCS") of the strings on all rings is the password. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.
For example, there are two strings on two arm rings: s1 = "abcdefg" and s2 = "zaxcdkgb". Then "acdg" is a LCS if you consider 'a' as the starting letter of s1, and consider 'z' or 'a' as the starting letter of s2. But if you consider 'd' as the starting letter of s1 and s2, you can get "dgac" as a LCS. If there are more than one LCS, the password is the one which is the smallest in lexicographical order.
Please find the password for Lara.
There are no more than 10 test cases.
In each case:
The first line is an integer n, meaning there are n (0 < n ≤ 10) arm rings.
Then n lines follow. Each line is a string on an arm ring consisting of only lowercase letters. The length of the string is no more than 8.
For each case, print the password. If there is no LCS, print 0 instead.
样例输入
2 abcdefg zaxcdkgb 5 abcdef kedajceu adbac abcdef abcdafc 2 abc def
样例输出
acdg acd 0
点我传送
n个头尾相接的字符串,寻找他们的最长公共子序列,若长度相同,则取字典序最小的。
因为n的范围很小只有10,并且字符的长度也很短只有8.所以大胆的暴力。用DFS处理出两个字符串中的所有公共子序列,用一个队列来保存,然后每次操作只取出原本在队列里子序列数量个字符串来DFS。总之就是一通瞎搞。。。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include