#include <stdio.h>
#include <string.h>
int fun();
char ch1[1010];
char ch2[1010];
int LCS[1010][1010];
int main()
{
int i = 0;
fgets(ch1, 1010, stdin);
while(ch1[0] != '#')
{
fgets(ch2, 1010, stdin);
i++;
printf("Case #%d: you can visit at most %d cities.\n", i, fun());
fgets(ch1, 1010, stdin);
}
}
int fun()
{
int len1 = strlen(ch1) - 1;
int len2 = strlen(ch2) - 1;
int i, j;
memset(LCS, 0, sizeof(LCS));
for(i = 1; i <= len1; i++)
for(j = 1; j <= len2; j++)
{
if(ch1[i-1] == ch2[j-1])
LCS[i][j] = LCS[i-1][j-1] + 1;
else if(LCS[i-1][j] >= LCS[i][j-1])
LCS[i][j] = LCS[i-1][j];
else
LCS[i][j] = LCS[i][j-1];
}
return LCS[len1][len2];
}
UVaOJ_10192 - Vacation
最新推荐文章于 2016-09-23 15:55:11 发布