#include <bits/stdc++.h> using namespace std; const int N = 1005; int dp[N][N]; // 可采用滚动数组优化 只保留i/i-1行 string s, t; int main() { while (cin >> s >> t) { int ns = s.length(), nt = t.length(); for (int i = 1; i <= ns; ++i) { for (int j = 1; j <= nt; ++j) { if (s[i - 1] == t[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1; else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); } } cout << dp[ns][nt] << '\n'; } return 0; }