Given two strings a and b of equal length, what‘s the longest string (s) that can be constructed such that it is a child of both?
A string x is said to be a child of a string y if x can be formed by deleting 0 or more characters from y.
For example, ABCD
and ABDC
has two children with maximum length 3, ABC
and ABD
. Note that we will not consider ABCD
as a common child because C
doesn‘t occur before D
in the second string.
Input format
Two strings, a and b, with a newline separating them.
Constraints
1<=|a|,|b|<=5000
All characters are upper cased and lie between ASCII values 65-90.
Output format
Print the length of the longest string s, such that s is a child of both a and b.
Sample Input 0
HARRY
SALLY
Sample Output 0
2
The longest possible string that is possible by deleting zero or more characters from HAPPY and SALLY is AY, whose length is 2.
Sample Input 1
AA
BB
Sample Output 1
0
AA and BB has no characters in common and hence the output is 0.
Sample Input 2
SHINCHAN
NOHARAAA
Sample Output 2
3
The longest string that can be formed between SHINCHAN and NOHAPAAA while maintaining the order is NHA.
Sample Input 3
ABCDEF
FBDAMN
Sample Output 3
2
BD is the longest child of the given strings.
这题一点都没有看懂是真的,今天的题,这道题可以说是最简单的模板题了,于是我现场上百度去control了一把。这题是最大公共子序。
现在还是什么都不懂。
原文地址:https://www.cnblogs.com/ineedyou/p/8496540.html