码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-03-03 15:35:42      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:sid   sep   一点   maximum   and   sed   from   简单的   input   

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 (最大公共子序)

标签:sid   sep   一点   maximum   and   sed   from   简单的   input   

原文地址:https://www.cnblogs.com/ineedyou/p/8496540.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!