信息奥赛一本通 怪盗基德的滑翔翼 (1286) 题解
代码:
#include <bits/stdc++.h>
using namespace std;
int ans, k, n, d[128][3];
void dp_1(int x) {
d[x][1] = 1;
for(int i = x - 1; i > 0; --i)
if(d[x][0] < d[i][0] && d[x][1] <= d[i][1]) d[x][1] = d[i][1] + 1;
ans = max(ans, d[x][1]);
if(x < n) dp_1(x + 1);
}
void dp_2(int x) {
d[x][2] = 1;
for(int i = x - 1; i > 0; --i)
if(d[x][0] > d[i][0] && d[x][2] <= d[i][2]) d[x][2] = d[i][2] + 1;
ans = max(ans, d[x][2]);
if(x < n) dp_2(x + 1);
}
int main() {
scanf("%d", &k);
while(k--) {
memset(d, 0, sizeof(d));
ans = 0;
scanf("%d", &n);
for(int i = 1; i <= n; ++i) scanf("%d", &d[i][0]);
dp_1(1); dp_2(1);
printf("%d\n", ans);
}
return 0;
}