1 #include<stdio.h>
2 #include<string.h>
3 #include<vector>
4 #include<algorithm>
5 const int inf = 0x3f3f3f3f ;
6 std::vector <int> g[1000 + 10] ;
7 int a[1111] ;
8 int dp[1111] ;
9 int n ;
10
11 int dfs (int id , int dep )
12 {
13 if (dp[id] != 1) return dp[id] ;
14 if (id == n - 1) return dp[id] ;
15 bool flag = 0 ;
16 for (int i = id + 1 ; i < n ; i ++) {
17 if (a[i] > a[id]) {
18 g[dep].push_back (dfs ( i , dep + 1) ) ;
19 flag = 1 ;
20 }
21 }
22 if (flag) {
23 int t = max_element (g[dep].begin () , g[dep].end () ) - g[dep].begin () ;
24 dp[id] += g[dep][t] ;
25 g[dep].clear () ;
26 }
27 return dp[id] ;
28 }
29
30 int main ()
31 {
32 // freopen ("a.txt" , "r" , stdin ) ;
33 while ( ~scanf ("%d" , &n) ) {
34 memset (dp , 0 , sizeof(dp)) ;
35 for (int i = 0 ; i < n ; i ++) scanf ("%d" , &a[i]) ;
36 for (int i = 0 ; i < n ; i ++) dp[i] = 1 ;
37 for (int i = n - 2 ; i >= 0 ; i --) { dfs (i , 0) ; }
38 int len = -inf ;
39 for (int i = 0 ; i < n ; i ++) len = std::max (len , dp[i]) ;
40 printf ("%d
" , len ) ;
41 }
42 return 0 ;
43 }