题解
2024-11-22 21:18:35
发布于:广东
3阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int n,a[3005],b[3005],dp[3005][3005];
int main(){
int ans = 0;
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 amax = 1;
for(int j = 1;j <= n;j ++){
dp[i][j] = dp[i - 1][j];
if (a[i] == b[j]) dp[i][j] = max(dp[i][j],amax);
else if (b[j] < a[i]) amax = max(amax,dp[i - 1][j] + 1);
}
}
for(int j = 1;j <= n;j ++){
ans = max(ans,dp[n][j]);
}
cout << ans << endl;
return 0;
}
这里空空如也
有帮助,赞一个