统计出最长得递增的子序列(nylg17)

问题描述:求一个字符串的最长递增子序列的长度如:dabdbf最长递增子序列就是abdf,长度为4

#include<stdio.h>

#include<string.h>

int main()

{

    int t,i;

    int n;

    char s[100002];

    int  a[100002];

    scanf("%d",&t);

    while(t--)

    {

        scanf("%s",s);

        n=strlen(s);

        for(i=0;i<n;i++)

        {

            int max=0;

            for(int j=i-1;j>=0;j--)

            {

                   if(s[i]>s[j] && a[j]>max)

                    max=a[j];

            }

            a[i]=max+1;

        }

        int count=0;

        for(i=0;i<n;i++)

          if(a[i]>count)

            count=a[i];

        printf("%d\n",count);

    }

}

posted @ 2012-05-07 23:23  coodle  阅读(100)  评论(0)    收藏  举报