Monotonically incrementing longest son Sequence

Source: Internet
Author: User
Monotonically incrementing maximum eldest son sequence time limit: 3000 MS | memory limit: 65535 kb difficulty: 4
Description
Returns the length of the longest incrementing sub-sequence of a string.
For example, the longest incremental sub-sequence of dabdbf is abdf and the length is 4.
Input
The first line has an integer of 0 <n <20, indicating that N strings are to be processed.
Next n rows, each line has a string, the length of the string will not exceed 10000
Output
Length of the longest incrementing sub-sequence of the output string
Sample Input
3aaaababcabklmncdefg
Sample output
13

7

The application of the basic idea of dynamic planning is controlled by an external loop, from local optimization to global optimization, and the local optimization is updated during the cycle process to achieve the end of the cycle, from local to global sublimation;

# Include <stdio. h> # include <string. h> # define max (A, B) A> B? A: B // calculate the maximum value # define max_len 10010 // The maximum supported sequence length int DP [max_len]; // Save the dynamic local solution char ch [max_len]; // Save the original data int main () {int T, <span style = "font-family: tahoma, Arial, sans-serif, simsun;"> Len; </span>

Int I, j; scanf ("% d", & T); While (t --) {int ans = 0; // scanf ("% s ", ch); Len = strlen (CH); for (I = 0; I <Len; I ++) // traverse each character {DP [I] = 1; // The minimum sequence length is 1for (j = 0; j <I; j ++) // For each I, traverse all characters before I {If (CH [J] <ch [I]) // if this character (CH [J]) is less than the current character (CH [I]) it indicates that DP [I] = max (DP [I], DP [J] + 1);} ans = max (ANS, DP [I]); // obtain the current global optimum (relative to I)} printf ("% d \ n", ANS);} return 0 ;}

Monotonically incrementing longest son Sequence

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.