monotonically increasing the eldest-son sequence

Source: Internet
Author: User

Title Description

The length of the longest increment subsequence of a string, such as: dabdbf the longest increment subsequence is abdf, length is 4

Enter a description

The first line is an integer 0<n<20, which indicates that there are n strings to process, followed by n rows, each line has a string, and the length of the string does not exceed 10000

Output description

The length of the longest increment subsequence of the output string

Input sample

3 AAAABABCABKLMNCDEFG

Output sample

1 3 7

Test code

1#include <stdio.h>2#include <string.h>3 #defineN 100104 5 CharStr[n];6 intMaxlen[n];7 intMainvoid)8 {9     intN, Len, I, J, Max;Ten  Onescanf"%d", &n); A GetChar (); -      while(n--) -     { the fgets (str, N, stdin); -Len =strlen (str); -maxlen[0] =1; -          for(i =1; i < Len; i++) +         { -Max =0; +              for(j = i-1; J >=0; j--) A             { at                 if(Str[i] > Str[j] && Max <Maxlen[j]) -                 { -Max =Maxlen[j]; -                 } -             } -Maxlen[i] = max +1; in         } -max = maxlen[0]; to          for(i =1; i < Len; i++) +         { -Max = (Maxlen[i] > max)?Maxlen[i]: max; the         } *printf"%d\n", max); $     }Panax Notoginseng     return 0; -}

monotonically increasing the eldest-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.