码迷,mamicode.com
首页 > 其他好文 > 详细

NYOJ 214 单调递增最长子序列(二)

时间:2015-07-02 22:35:12      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

#include<stdio.h>
#include<string.h>
const int max=10001;
int dp[max];
char s[max];
int maxn;
void LTCS()
{
  int len;
  memset(dp,0,sizeof(dp));
  len=strlen(s);
  for(int i=0;i<len;i++)
  {
    dp[i]=1;
    for(int j=0;j<i;j++)
    {
      if(s[i]>s[j] && dp[i]<dp[j]+1 )
        dp[i]=dp[j]+1;
    }
  }
  maxn=0;
  for(int i=0;i<len;i++)
  if(maxn<dp[i])
    maxn=dp[i];
}
int main()
{
  int n;
  scanf("%d",&n);
  while(n--)
  {
    scanf("%s",s);
    LTCS();
    printf("%d\n",maxn);
  }
}

NYOJ 214 单调递增最长子序列(二)

标签:

原文地址:http://www.cnblogs.com/mycapple-zgs-111411/p/4617285.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!