Dynamic programming--the longest common ascending subsequence LCIs

Source: Internet
Author: User

Problem

Given two sequences A and B, the subsequence of a sequence is a subset of the number of numbers formed from the original sequence in the order of gradual increment of the index, and if the numerical size of the subsequence is gradually ascending to the ascending sub-sequence, if the two subsequence A1 and B1 are the same, then the common subsequence of A and B is a1/b1. Find the longest common ascending subsequence of A and B.

Analysis
In conjunction with the longest common subsequence and the longest ascending subsequence to solve this problem, the definition state Dp[i][j] represents the length of the longest public ascending subsequence of the first I character in a string and the first J character in string B and ends with B[j] . Then there is the state transfer equation: "In the design of dynamic planning state, we should describe the state information in a simple and detailed"

if (a[i]! = b[j])    dp[i][j] = Dp[i-1][j];else    dp[i][j] = max (dp[i-1][k]) + 1; (1 <= k <= j-1 && b[j] > B[k])

Realize

for (int i = 1; I <= n; i + +) {    int maxn = 0;    for (int j = 1; j <= M; j + +) {        if (A[i]!=b[j])            dp[i][j] = dp[i-1][j];        if (A[i] > B[j])            MAXN = max (MAXN, Dp[i-1][j]);        if (a[i] = = B[j])            dp[i][j] = maxn + 1;    }} int mm = 0;for (int i = 1;i <= m; i + +)    mm = max (mm, dp[n][i]);

Dynamic programming--the longest common ascending subsequence LCIs

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.