DP优化经典
设 dp[i][j] 表示以 b[j] 结尾的 a[i] 以前的 LCIS 的长度
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#define inf 0x3f3f3f3f
using namespace std;
const int MAXN = 3005;
int n, dp[MAXN][MAXN], ans;
long long a[MAXN], b[MAXN];
int main() {
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
for(int i = 1; i <= n; i++) {
cin >> b[i];
}
a[0] = b[0] = -inf;
for(int i = 1; i <= n; i++) {
int val = 0;
for(int j = 1; j <= n; j++) {
if(a[i] == b[j]) {
dp[i][j] = val + 1;
}else dp[i][j] = dp[i - 1][j];
if(b[j] < a[i]) val = max(val, dp[i - 1][j]);
ans = max(ans, dp[i][j]);
}
}
cout << ans << endl;
return 0;
}