提交时间:2023-11-25 11:22:59

运行 ID: 112273

#include <bits/stdc++.h> using namespace std; int a[10005]; int b[10005]; int dp[10005][10005]; int main() { int n,m; 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++) { for(int j = 1;j <= n;j++) { dp[i][j] = max(dp[i-1][j],dp[i][j-1]); if(a[i] == b[j]) { dp[i][j] = max(dp[i][j],dp[i-1][j-1] + 1); } } } cout << dp[n][n]; return 0; }