HDU 4681 string (DP, LCs | multi-school 8)

Source: Internet
Author: User

From http://blog.csdn.net/shuangde800

Question: Click to open the link

Question

3 strings A, B, and C are provided. You need to find a string d to meet the following requirements:
A) D is the subsequence of.
B) D is the subsequence of B.
C) C is the substring of D.
Returns the maximum length of D.
Note the differences between subsequences and substrings. subsequences are discontinuous and strings are continuous.

Ideas

We can see from the question that C must be a subsequence of A and B. Assume that C has only one subsequence in A and B. Let's look at the example below:

Abcdefdeg

Acebdfgh

Cf

We can see that "CF" is in the range [3, 6] of string a and in the range [2, 6] of string B (yellow background)

Because the requested C is a substring of D, other letters in the yellow interval cannot be obtained.

The longest length is equal to the longest common sub-sequence length of the red and blue areas + the length of C

The f (I, j) of the LCS algorithm is used to obtain the longest Public String Of the first I and J of the second string.
The red part can be obtained directly.
In the latter part, you only need to reverse the two strings and then find them at LCS once.

Finally, find all the subsequences of C in A and B, and enumerate them to obtain the answer.

 

Code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.