1. 程式人生 > >寒假。3.3.G - Common Child (最大公共子序)

寒假。3.3.G - Common Child (最大公共子序)

int 真的 style clas line post while doesn 是什麽

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了一把。這題是最大公共子序。

現在還是什麽都不懂。

寒假。3.3.G - Common Child (最大公共子序)