寒假。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

时间: 2024-11-05 20:28:01

寒假。3.3.G - Common Child (最大公共子序)的相关文章

HDU 1159 Common Subsequence 最大公共子序列

Problem Description A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = <x1, x2, ..., xm> another sequence Z = <z1, z2, ..., zk> is a subsequence of X if there exists a stri

Common Child

题目如下: Sample Input #0 HARRY SALLY Sample Output #0 2 The longest possible subset of characters that is possible by deleting zero or more characters from HARRY andSALLY is AY, whose length is 2. Sample Input #1 AA BB Sample Output #1 0 AA and BB has n

Common Subsequence 最大公共子序列问题

Problem Description A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = <x1, x2, ..., xm> another sequence Z = <z1, z2, ..., zk> is a subsequence of X if there exists a stri

【HackerRank】Common Child (LCS)最长公共子序列

Given two strings a and b of equal length, what's the longest string (S) that can be constructed such that S is a child to both a and b. String x is said to be a child of string y if x can be formed by deleting 0 or more characters from y Input forma

HackerRank - Common Child

Longest Common Subsequence in disguise. Python impl. has TLE in one case. And C++ is fine. #include <cmath> #include <cstdio> #include <vector> #include <unordered_set> #include <string> #include <iostream> #include <

寒假训练——搜索 G - Xor-Paths

There is a rectangular grid of size n×mn×m . Each cell has a number written on it; the number on the cell (i,ji,j ) is ai,jai,j . Your task is to calculate the number of paths from the upper-left cell (1,11,1 ) to the bottom-right cell (n,mn,m ) meet

Methods and systems for sharing common job information

Apparatus and methods are provided for utilizing a plurality of processing units. A method comprises selecting a pending job from a plurality of unassigned jobs based on a plurality of assigned jobs for the plurality of processing units and assigning

Master the 10 Most Common Python Programming Problems - 10大最常见的Python编程错误

http://blog.csdn.net/pipisorry/article/details/45175457 Introduction 本文介绍python编程中很难捕捉10大错误 (Note: This article is intended for a more advanced audience than Common Mistakes of Python Programmers, which is geared(适合) more toward those who are newer t

[ZZ]10 Most Common Mistakes that Python Programmers Make

About Python Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application D