#include<cstdio> #include<cstring> using namespace std; //LCSub问题,水题,滚动数组优化空间 int main() { char str[1005],str1[1005]; int dp[2][1005]; int n,m; while(~scanf("%s %s",str,str1)) { memset(dp,0,sizeof(dp)); n = strlen(str); m = strlen(str1); for(int i = 1; i<=n; ++i) for(int j = 1; j<=m; ++j) dp[i%2][j] = (str[i-1]==str1[j-1])?(dp[(i-1)%2][j-1] + 1):(dp[(i-1)%2][j]>dp[i%2][j-1]?dp[(i-1)%2][j]:dp[i%2][j-1]); printf("%d\n",dp[n%2][m]); } return 0; }