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
| #include <iostream> using namespace std;
const int N = 110; int a[N], f[N];
int main() { int K; cin >> K; while (K--) { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; int res = 0; for (int i = 1; i <= n; i++) { f[i] = 1; for (int j = 1; j < i; j++) { if (a[j] < a[i]) { f[i] = max(f[i], f[j] + 1); } } res = max(res, f[i]); }
for (int i = n; i >= 1; i--) { f[i] = 1; for (int j = n; j > i; j--) { if (a[j] < a[i]) { f[i] = max(f[i], f[j] + 1); } } res = max(res, f[i]); } cout << res << endl; } return 0; }
|