#include<iostream> #include<algorithm> #include<cstring> using namespace std ; const int N = 1010 ; int n , m; char a[N] ; char b[N] ; int f[N][N] ; int main(){ cin >> n >> m ; scanf("%s%s" ,a +1 , b + 1);\\从第1个位置开始读入字符串 for(int i = 1 ; i <= n ; i ++){\\对a串每一个字符进行遍历 for(int j = 1 ; j <= m ; j ++){\\对b串每一个字符进行遍历 f[i][j] = max(f[i][j-1] , f[i-1][j]); if(a[i] == b[j]) f[i][j] = max(f[i][j] , f[i-1][j-1] + 1); } } cout << f[n][m] << endl ; return 0 ; }