4
2 2 1 3
2 1 2 3
输出样例:
2
#include <bits/stdc++.h>
using namespace std;
const int N = 3010;
int a[N], b[N];
int g[N][N], f[N][N];
int n;
int res;
int main()
{
cin >> n;
for(int i = 1;i <= n;i++) cin >> a[i];
for(int i = 1;i <= n;i++) cin >> b[i];
for(int i = 1;i <= n;i++)
{
int maxv = 1;
for(int j = 1;j <= n;j++)
{
f[i][j] = f[i - 1][j];
if(a[i] == b[j]) f[i][j] = max(f[i][j], maxv);
if(a[i] > b[j]) maxv = max(maxv, f[i - 1][j] + 1);
}
}
for(int i = 1;i <= n;i++) res = max(f[n][i], res);
cout << res << endl;
return 0;
}