C++ 代码
#include<iostream>
#include<cstring>
using namespace std;
int m,n,fl_s[n];
string s1,s2;
int main(){
cin>>m>>n;
cin>>s1>>s2;
memset(fl_s,0,sizeof fl_s);
for(int i=0;i<m;++i){
int fl=0;
char c=s1[i];
for(int j=0;j<n;++j){
int t=fl;
if(fl<fl_s[j]) fl=fl_s[j];
if(s2[j]==c) fl_s[j]=t+1;
}
}
int res=0;
for(int j=0;j<n;++j) res=max(res,fl_s[j]);
cout<<res;
return 0;
}