Problem 757
Print Longest Common Subsequence
Hard · 30 pts · String, Dynamic Programming
Problem
A common subsequence of strings A and B is a string that is a subsequence of both. Print a longest common subsequence; if several different strings have the maximum length, print the lexicographically smallest of them, and print NONE if the strings share no character. Compute L[i][j], the LCS length of the suffixes A[i..] and B[j..]. Then build the answer greedily: at each step try letters from a to z and take the first letter whose next occurrences in A and B still leave a common subsequence of the needed remaining length.
Input
The first line contains A. The second line contains B. Both use lowercase letters.
Output
Print the lexicographically smallest longest common subsequence, or NONE.
Constraints
1 <= |A|, |B| <= 1000
Example input
abcbdab bdcaba
Example output
bcab
Explanation
For abcbdab and bdcaba, the longest common subsequences have length 4: bcba, bcab and bdab. The lexicographically smallest of them is bcab.