dp ,经典LCS,你懂的,不解释
//dp 经典的LCS问题。对于s1,s2,如果c(s1)=c(s2),则f(s1,s2)=f(s1-1,s2-1,)+1,如果c(s2)!=c(s1),则
//f(s1,s2)=max{f(s1-1,s2),f(s1,s2-1)},边界是f(s1,0)=0,f(0,s2)=0;
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=1000;
const int inf=1<<31;
char x[maxn],y[maxn];
int lcs[maxn][maxn];
int main()
{
while(scanf("%s%s",x,y)!=EOF)
{
int lenx=strlen(x);
int leny=strlen(y);
int mlen=lenx>leny?lenx:leny;
int i,j,ti,tj;
for(i=1;i<=mlen;i++)
{
lcs[i][0]=0;
lcs[0][i]=0;
}
for(i=1;i<=lenx;i++)
{
ti=i-1; //相当于映射,从虚构的位置,得到在数组中的实际位置
for(j=1;j<=leny;j++)
{
tj=j-1;
if(x[ti]==y[tj])
lcs[i][j]=lcs[i-1][j-1]+1;
else
lcs[i][j]=lcs[i-1][j]>lcs[i][j-1]?lcs[i-1][j]:lcs[i][j-1];
}
}
cout<<lcs[lenx][leny]<<endl;
}
return 0;
}