zoukankan      html  css  js  c++  java
  • NYOJ 17(LIS)

     1 #include <cstdio>
     2 #include <cstring>
     3 using namespace std;
     4 
     5 char str[10010];
     6 int ans[10010];
     7 
     8 int main()
     9 {
    10     int i,j,k;
    11     int T;
    12     scanf("%d%*c",&T);
    13     while(T--)
    14     {
    15         memset(str,0,sizeof(str));
    16         memset(ans,0,sizeof(ans));
    17 
    18         scanf("%s",str);
    19         int res = 1;//初始化为1就AC
    20         ans[0] = 1;
    21         for(i=1; str[i]!='\0'; i++)
    22         {
    23             ans[i] = 1;//重要
    24             int max = 0;//定义在里面
    25 
    26             //for(j=0; j<i; j++)
    27            /// if(str[j]<str[i]&&ans[j]>max)
    28             //    max = ans[j];
    29             //max必须初始化为0,否则如果内层for一次也不执行的话就错了
    30           //  ans[i] = max + 1;
    31 
    32             
    33             for(j=0; j<i; j++)
    34             if(str[j]<str[i]&&ans[i]<ans[j]+1)
    35                 ans[i] = ans[j]+1;
    36             if(res<ans[i])
    37                 res =ans[i];
    38         }
    39        printf("%d\n",res);
    40     }
    41     return 0;
    42 }
  • 相关阅读:
    UITextField的总结
    【实战】登录界面
    点分治学习
    2020/3/1
    2020/2/29
    2020/2/28
    2020/2/27
    2020/2/27
    最小树形图
    Ch’s gift HDU6162
  • 原文地址:https://www.cnblogs.com/hxsyl/p/2516367.html
Copyright © 2011-2022 走看看