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 }

 

posted @ 2012-05-24 12:59  加拿大小哥哥  阅读(230)  评论(0编辑  收藏  举报