匪常简单
2024-08-03 13:05:31
发布于:广东
61阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
int n, a[N], b[N];
int f[N][N], ans;
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 maxn = 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], maxn);
if (b[j] < a[i]) maxn = max(maxn, f[i - 1][j] + 1);
}
}
for (int i = 1; i <= n;i++) ans = max(ans, f[n][i]);
cout << ans << endl;
return 0;
}
这里空空如也
有帮助,赞一个