快捷搜索:

zoj1733(最长公共子序列)

很简单的一道题

#include

#include

#include

char x[10005],y[10005];

int c[1005][1005];

int Lcs_length( char *str1, char *str2)

{

int len1 = strlen(str1),

len2 = strlen(str2);

int i,j;

for( i = 1; i = c[i][j-1])

c[i][j] = c[i-1][j];

else c[i][j] = c[i][j-1];

}

return c[len1][len2];

}

void Find_Lcs( char *str1, char *str2)

{

int i,j,length;

int len1 = strlen(str1),

len2 = strlen(str2);

length = Lcs_length(str1, str2);

printf("%d\n", length);

}

int main()

{

while(scanf("%s%s",x,y) != EOF){

Find_Lcs(x,y);

memset(x,0,sizeof(x));

memset(y,0,sizeof(y));

memset(c,0,sizeof(c));

}

return 0;

}

您可能还会对下面的文章感兴趣: