#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<cctype>
#include<map>
#include<stack>
#include<cstdlib>
#include <queue>
#include <vector>
#include<algorithm>
#define ll long long
#define sc scanf
#define pf printf
#define Pi 2*acos(0.0)
using namespace std;
long long int n,m,lcs[2000][2000];
int main()
{
string s1,s2;
long cs=1;
while(getline(cin,s1))
{
if(s1=="#")
break;
getline(cin,s2);
n=s1.size();
m=s2.size();
long i,j;
for( i=1;i<=n;i++)
for( j=1;j<=m;j++)
{
if(s1[i-1]==s2[j-1])
lcs[i][j]=lcs[i-1][j-1]+1;
else
lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
}
printf("Case #%ld: you can visit at most %lld cities.\n",cs++,lcs[n][m]);
}
return 0;
}
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<cctype>
#include<map>
#include<stack>
#include<cstdlib>
#include <queue>
#include <vector>
#include<algorithm>
#define ll long long
#define sc scanf
#define pf printf
#define Pi 2*acos(0.0)
using namespace std;
long long int n,m,lcs[2000][2000];
int main()
{
string s1,s2;
long cs=1;
while(getline(cin,s1))
{
if(s1=="#")
break;
getline(cin,s2);
n=s1.size();
m=s2.size();
long i,j;
for( i=1;i<=n;i++)
for( j=1;j<=m;j++)
{
if(s1[i-1]==s2[j-1])
lcs[i][j]=lcs[i-1][j-1]+1;
else
lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
}
printf("Case #%ld: you can visit at most %lld cities.\n",cs++,lcs[n][m]);
}
return 0;
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন