From http://blog.csdn.net/shuangde800
Question: Click to open the link
Theme
Returns the longest return string of a string. If multiple results exist, the minimum Lexicographic Order is output.
Ideas
We all know that we can calculate the maximum length of a string in the descending order of a string and the longest common subsequence of the original string.
However, this question should not only be output to the text string, but also be the smallest Lexicographic Order, so it is quite difficult.
Set str1 to a forward string and str2 to a reverse string.
F [I] [J]. Len indicates the first I bit of str1, the first J bit of str2, and the longest length of the common substring.
F [I] [J]. Str indicates the first I bit of str1, the first J bit of str2, and the minimum lexicographic string of the longest common substring.
Status transfer is similar to normal LCS, but it only adds the string with the minimum record Lexicographic Order
However, the final f [I] [J]. STR is not necessarily the answer, because the longest common subsequence calculated is not necessarily a return string.
For example:
Kfclbckibbibjccbej
Jebccjbibbikcblcfk
Bcibbibc is their LCS, but it is not a reply string
However, the first LEN/two must be the first half of the input string.
After knowing the first LEN/2, you can directly construct the second half of the input string.
Note the parity of Length
Code