#K3856. Longest Common Interleaved Subsequence
Longest Common Interleaved Subsequence
Longest Common Interleaved Subsequence
You are given three strings S1, S2 and T consisting of lowercase English letters. Your task is to determine the maximum length of a common subsequence that can be obtained by interleaving (i.e. merging while preserving individual order) S1 and S2 into a new string M, and then finding a subsequence in common between M and T.
More formally, you must choose an interleaving of S1 and S2 (i.e. a string M such that M is a shuffle of S1 and S2 with the order of characters in S1 and S2 preserved) so that the length of the longest common subsequence (LCS) between M and T is maximized. Output the maximum possible length of this LCS.
Note: The interleaving M is uniquely determined by the order in which you choose characters from S1 and S2, and you must use all characters from both S1 and S2.
Example 1: For S1 = "abc", S2 = "def" and T = "adbecf", one optimal interleaving is "adbecf" which has an LCS with T of length 6.
inputFormat
The input consists of three lines:
- The first line contains the string S1.
- The second line contains the string S2.
- The third line contains the string T.
outputFormat
Output a single integer, the maximum length of the longest common subsequence between the interleaved string M (formed by S1 and S2) and T.
## sampleabc
def
adbecf
6