文章
37
粉丝
1
获赞
353
访问
24.6k
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
vector<int> a(n+1);
vector<int> b(n+1);
for(int i = 0 ; i < n; i++){
cin>>a[i];
}
for(int i = 0 ; i < m; i++){
cin>>b[i];
}
vector<vector<int>> dp(n+1,vector<int>(n+1));
int ans = 0;
//dp[i][j]:以a的第i个字符,和b的第j个字符结尾的字符串组成的最长连续子数组的长度
for(int i = 1 ; i <= n; i++){
for(int j = 1 ; j <= m; j++){
if(a[i-1] == b[j-1]){
dp[i][j] = dp[i-1][j-1]+1;
}
else{
dp[i][j] = 0;
}
ans = max(ans,dp[i][j]);
}
}
cout<<ans<<endl;
}
登录后发布评论
暂无评论,来抢沙发