题解 | #公共子串计算#
公共子串计算
https://www.nowcoder.com/practice/98dc82c094e043ccb7e0570e5342dd1b
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string s1,s2;
cin>>s1>>s2;
int n1=s1.size();
int n2=s2.size();
s1=' '+s1;
s2=' '+s2;
int res=0;
vector<vector<int>>dp(n1+1,vector<int>(n2+1,0));
for(int i=1;i<=n1;i++){
for(int j=1;j<=n2;j++){
if (s1[i]==s2[j]) {
dp[i][j]=max(dp[i-1][j-1]+1,dp[i][j]);
if(dp[i][j]>res)res=dp[i][j];
}
}
}
cout<<res;
}
// 64 位输出请用 printf("%lld")
