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

Posted ineedyou

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了寒假。3.3.G - Common Child (最大公共子序)相关的知识,希望对你有一定的参考价值。

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 (最大公共子序)的主要内容,如果未能解决你的问题,请参考以下文章

Maven多模块项目循环依赖问题

二叉排序树BST

yii 自带RBAC

中北第二小时的寒假作业怎么写

YII框架自带RBAC

第一次寒假作业 汇总