#include<iostream>
#include<cstdio>
#include<cstring>
#define pf printf
#define sf scanf
#define up 1
#define left 2
#define diag 3
#define sz 1009
using namespace std;
char x[sz],y[sz];
int c[sz][sz], b[sz][sz];
void build_LCS(int m, int n)
{
int i,j;
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
if(x[i-1] == y[j-1])
{
c[i][j] = c[i-1][j-1] + 1;
b[i][j] = diag;
}
else if(c[i-1][j] >= c[i][j-1])
{
c[i][j] = c[i-1][j];
b[i][j] = up;
}
else
{
c[i][j] = c[i][j-1];
b[i][j] = left;
}
}
}
// for(i=0;i<=m;i++)
// {
// for(j=0;j<=n;j++)
// {
// pf("%d ",c[i][j]);
// }
//
// pf("\n");
// }
}
int main()
{
int tc=0;
while(gets(x) and x[0]!='#')
{
int m=strlen(x);
gets(y);
int n=strlen(y);
build_LCS(m,n);
pf("Case #%d: you can visit at most %d cities.\n",++tc,c[m][n]);
}
return 0;
}
Comments
Post a Comment