uva 11456 - Trainsorting Solution
uva 11456 - Trainsorting Solution
#include<algorithm>
#include<cstdio>
using namespace std;
int main() {
int A[2000], Ma[2000], Mb[2000], N, T, sum, ans, i, j;
scanf("%d", &T);
while(T--) {
scanf("%d", &N);
for (i = 0; i < N; i++)
scanf("%d", &A[i]);
ans = 0;
for (i = N - 1; i >= 0; i--) {
Ma[i] = 1;
Mb[i] = 1;
for (j = i + 1; j < N; j++) {
if (A[i] < A[j]) {
Ma[i] = max(Ma[j] + 1, Ma[i]);
}
if (A[i] > A[j]) {
Mb[i] = max(Mb[j] + 1, Mb[i]);
}
}
ans = max(ans, Ma[i] + Mb[i] - 1);
}
printf("%d\n", ans);
}
return 0;
}
Comments
Post a Comment