Longest public sub-sequence and longest public continuous sub-sequence-Andrew's log-Netease blog

Source: Internet
Author: User

Longest public sub-sequence and longest public continuous sub-sequence-Andrew's log-Netease blog

Longest Common subsequence and longest common continuous subsequence  

2012-08-26 16:02:16| Category:Algorithm Learning| Tag:  |Font SizeLargeMediumSmall Subscription

1. longest Common subsequence (not consecutive)
define F (m, n) the length of the longest subsequence between xm and YN
F (M, 0) = f (0, m) = 0
If XM! = YN, then f (m, n) = max {f (m-1, n), F (M, n-1)}
If XM = YN, F (m, n) = f (S-1, n-1) + 1
the problem lies in F (m, n ). Use Bottom-up DP according to the formula.

2. longest consecutive substring (must be consecutive)
define F (m, n) it is the length of the longest substring between xm and YN and ends with XM & YN. Because the requirements are continuous, when defining F, an extra requirement string ends at XM & YN
F (M, 0) = f (0, m) = 0
If XM! = YN, then f (m, n) = 0
If XM = YN, F (m, n) = f (S-1, n-1) + 1
because the longest string does not necessarily end at the end of XM/YN, therefore, all possible F (p, q) | 0

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.