寒假。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了一把。这题是最大公共子序。

现在还是什么都不懂。

转载于:https://www.cnblogs.com/ineedyou/p/8496540.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值