#include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; int main() { int n, m; string str1, str2; cin >> str1 >> str2; n = str1.size(); m = str2.size(); vector<vector<int> >dp = vector<vector<int> >(n + 1, vector<int>(m + 1, 0)); for (int i = 0; i < dp[0].size(); ++i) dp[0][i] = 0; for (int j = 0; j < n + 1; ++j) dp[j][0] = 0; for(int i=0;i<n;++i) for (int j = 0; j < m; ++j) { if (str1[i] == str2[j]) dp[i+1][j+1] = dp[i][j] + 1; else { dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]); } } cout << dp[n][m] << endl; system("pause"); return 0; }