1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 int a[500][500]; 9 int main()10 {11 string s1,s2;12 while(cin>>s1>>s2)13 {14 int k1=s1.length();15 int k2=s2.length();16 memset(a,0,sizeof(a));17 for(int i=1; i<=k1; i++)18 {19 for(int j=1; j<=k2; j++)20 {21 if(s1[i-1]==s2[j-1])22 {23 a[i%2][j]=a[(i-1)%2][j-1]+1;24 }25 else26 {27 a[i%2][j]=max(a[(i-1)%2][j],a[i%2][j-1]);28 }29 }30 }31 printf("%d\n",a[k1%2][k2]);32 }33 return 0;34 }