http://ac.jobdu.com/problem.php?pid=1042
#include <stdio.h>
#include <cstring>
#include <algorithm>
int main(){
//freopen("in/1042.in","r",stdin);
int dp[101][101],m,n;
char a[101],b[101];
while(scanf("%s",a)!=EOF){
scanf("%s",b);
m = (int) strlen(a);
n = (int) strlen(b);
for (int i = 0; i <=m; ++i) {
dp[i][0] = 0;
}
for (int i = 0; i <=n; ++i) {
dp[0][i] = 0;
}
for (int i = 1; i <=m; ++i) {
for (int j = 1; j<=n; ++j) {
if(a[i-1] == b[j-1]) {
dp[i][j] = dp[i-1][j-1] + 1;
}else{
dp[i][j] = std::max(dp[i-1][j],dp[i][j-1]);
}
}
}
printf("%d\n",dp[m][n]);
}
}