XOJ 1030 月下老人的苦恼

links:http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1030
#include <stdio.h>
int m,n;
char man[1001],woman[1001];
int match[1001][1001];
void pipei();
int main(){
scanf("%d%d",&m,&n);
int i,j;
for(i=0;i<=m;i++){
scanf("%c",&man[i]);
}
for(i=0;i<=n;i++){
scanf("%c",&woman[i]);
}

pipei();
return 0;
}

void pipei(){
int i,j;
for(i=0;i<=m;i++){
match[i][0]=0;
}
for(i=0;i<=n;i++){
match[0][i]=0;
}
for(i=1;i<=m;i++){
for(j=1;j<=n;j++){
if(man[i]==woman[j])
match[i][j]=match[i-1][j-1]+1;
else if(match[i][j-1]>match[i-1][j])
match[i][j]=match[i][j-1];
else
match[i][j]=match[i-1][j];
}
}
printf("%d\n",match[m][n]);
}
原文地址:https://www.cnblogs.com/WangCT/p/2328933.html