1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| #include<bits/stdc++.h>
using namespace std;
#define Max 2005
int main()
{
int a[Max], x[Max], y[Max];
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int T;
cin >> T;
while(T--){
int n;
cin >> n;
for(int i = 0; i < n; i++){
cin >> a[i];
}
int ans = 0;
for(int i = n-1; i >=0 ; i--){
x[i] = 1;
y[i] = 1;
for(int k = i+1; k < n; k++){
if(a[i] < a[k]){
x[i] = max(x[k]+1, x[i]);
}
if(a[i] > a[k]){
y[i] = max(y[k]+1, y[i]);
}
}
ans = max(ans, x[i]+y[i]-1);
}
cout << ans << endl;
}
return 0;
}
|
No comments:
Post a Comment