题目考点:最长上升子序列LIS
最长上升子序列 (LIS) 详解+例题模板 (全)-CSDN博客
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n; // 楼房的个数
int a[N]; // 楼房的高度数组
// 数组模拟栈
int f[N], fl;
int g[N], gl;
int res;
int main() {
int T;
cin >> T;
while (T--) {
memset(f, 0, sizeof f);
memset(g, 0, sizeof g);
fl = 0, gl = 0;
cin >> n;
for (int i = 1; i <= N; i++) {
cin >> a[i];
}
f[++f1] = a[1];
for (int i = 2; i <= n; i++) {
if (a[i] > f[f1]) {
f[++f1] = a[i];
}
else
*lower_bound(f + 1, f + 1 + f1, a[i]) = a[i];
}
res = f1;
g[++g1] = a[n];
for (int i = n - 1; i >= 1; i--) {
if (a[i] > g[g1]) {
g[++g1] = a[i];
}
else
*lower_bound(g + 1, g + 1 + g1, a[i]) = a[i];
}
res = max(res, g1);
print("%d\n", res);
}
return 0;
}