/* -*- coding: utf-8 -*- * * 209.cc: No.209 Longest Mountain Subsequence - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100; /* typedef */ /* global variables */ int as[MAX_N]; int dp0[MAX_N][MAX_N], dp1[MAX_N][MAX_N]; /* subroutines */ /* main */ int main() { int tn; cin >> tn; while (tn--) { int n; cin >> n; for (int i = 0; i < n; i++) cin >> as[i]; memset(dp0, 0, sizeof(dp0)); memset(dp1, 0, sizeof(dp1)); for (int i = 0; i < n; i++) dp0[i][i] = dp1[i][i] = 1; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) { int aij = as[j] - as[i]; if (aij > 0) { for (int k = 0; k <= i; k++) if (dp0[k][i] > 0) { int aki = as[i] - as[k]; int d = dp0[k][i] + 1; if (aij > aki && dp0[i][j] < d) dp0[i][j] = d; } } } for (int i = n - 1; i >= 0; i--) for (int j = i - 1; j >= 0; j--) { int aij = as[j] - as[i]; if (aij > 0) { for (int k = n - 1; k >= i; k--) if (dp1[k][i] > 0) { int aki = as[i] - as[k]; int d = dp1[k][i] + 1; if (aij > aki && dp1[i][j] < d) dp1[i][j] = d; } } } int maxsum = 0; for (int i = 0; i < n; i++) { int maxd0 = 0, maxd1 = 0; for (int j = 0; j <= i; j++) if (maxd0 < dp0[j][i]) maxd0 = dp0[j][i]; for (int j = n - 1; j >= i; j--) if (maxd1 < dp1[j][i]) maxd1 = dp1[j][i]; int sum = maxd0 + maxd1 - 1; if (maxsum < sum) maxsum = sum; } printf("%d\n", maxsum); } return 0; }