-
Notifications
You must be signed in to change notification settings - Fork 0
/
11456.cpp
109 lines (103 loc) · 2.76 KB
/
11456.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* BATPROBATPROBATPROBATPROBATPROBATPROBATPROBATPROBATPROBATPROBATPR
* BATPROBATPROBATPROBATPROBATPROBATPROBATPROBATPROBATPROBATPROBATPR
* BAT. `PROBATPROBA|\___/|TPROBATPROB' .ATP
* BATPR. `OBATPROBAT| |PROBATPROBA' .TPROB
* BATPRO. `BATPROBA/ \TPROBATP' .ROBATP
* BATPROB. .ATPROBA
* BATPROB' `ATPROBA
* BATPRO' `BATPRO
* BATPROBATPROBATP`---._ _.---'ROBATPROBATPROBA
* BATPROBATPROBATPROBATPR--. .--OBATPROBATPROBATPROBATP
* BATPROBATPROBATPROBATPROBAT-. .-PROBATPROBATPROBATPROBATPRO
* BATPROBATPROBATPROBATPROBATPRO. .BATPROBATPROBATPROBATPROBATPRO
* BATPROBATPROBATPROBATPROBATPROB\ /ATPROBATPROBATPROBATPROBATPROBA
* BATPROBATPROBATPROBATPROBATPROBAVTPROBATPROBATPROBATPROBATPROBATP
*
*/
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <sstream>
#include <cstring>
#include <cctype>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
using namespace std;
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
#define FN(s,c) (int)s.find(c)
#define FOR(i,e) for (int i = 0; i < e; i++)
#define MFOR(i,s,e) for (int i = s; i <= e; i++)
#define ROF(i,s) for (int i = s-1; i >= 0; i--)
#define MROF(i,s,e) for (int i = s; i >= e; i--)
#define IT(it,v) for(it=v.begin();it!=v.end();it++)
#define TI(it,v) for(it=v.rbegin();it!=v.rend();it++)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define FILL(a,v) memset(a,v,sizeof(a))
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> II;
/*************************************************/
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
int t;
cin >> t;
FOR(z, t)
{
int n;
cin >> n;
int arr[2010];
FOR(i, n)
{
cin >> arr[i];
}
int l[2010], d[2010];
FILL(l, 0);
FILL(d, 0);
l[n - 1] = 1;
d[n - 1] = 1;
int ans = (n > 0 ? 1 : 0);
MROF(i, n-2, 0)
{
// longest increasing subsequence
int lis = 1;
MFOR(j,i+1, n-1)
{
if (arr[j] > arr[i]) {
lis = max(lis, l[j] + 1);
}
}
l[i] = lis;
// longest decreasing subsequence
int lds = 1;
MFOR(j, i+1, n-1)
{
if (arr[j] < arr[i]) {
lds = max(lds, d[j] + 1);
}
}
d[i] = lds;
ans = max(ans, lis + lds - 1);
}
cout << ans << endl;
}
return 0;
}