Sample Input
abcfbc abfcab programming contest abcd mnp
Sample Output
4 2 0
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int dp[1005][1005];
char s[1000],t[1000];
int main()
{
while(~scanf("%s %s",s,t))
{
getchar();
int ls=strlen(s);
int lt=strlen(t);
int i,j;
memset(dp,0,sizeof(dp));
for(i=0;i<ls;i++)
{
for(j=0;j<lt;j++)
if(s[i]==t[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]);
}
printf("%d\n",dp[ls][lt]);
}
return 0;
}