#include<bits/stdc++.h>
#define REP(i,n) for(i=0;i<n;i++)
using namespace std;
long dp[102][102],n,m;
string s[102],s1[102];
long call(long i,long j)
{
if(i>=n||j>=m)return 0;
if(dp[i][j]!=-1)return dp[i][j];
long ans=0;
if(s[i]==s1[j])
ans=1+call(i+1,j+1);
else
{
long val1=call(i+1,j);
long val2=call(i,j+1);
ans=max(val1,val2);
}
dp[i][j]=ans;
return dp[i][j];
}
int main()
{
long tst=1;
while(cin>>n>>m)
{
memset(dp,-1,sizeof(dp));
long i,p;
if(n==0&&m==0)break;
REP(i,n)
cin>>s[i];
REP(i,m)
cin>>s1[i];
cout<<"Twin Towers #"<<tst++<<endl;
cout<<"Number of Tiles : "<<call(0,0)<<endl;
cout<<endl;
}
return 0;
}
#define REP(i,n) for(i=0;i<n;i++)
using namespace std;
long dp[102][102],n,m;
string s[102],s1[102];
long call(long i,long j)
{
if(i>=n||j>=m)return 0;
if(dp[i][j]!=-1)return dp[i][j];
long ans=0;
if(s[i]==s1[j])
ans=1+call(i+1,j+1);
else
{
long val1=call(i+1,j);
long val2=call(i,j+1);
ans=max(val1,val2);
}
dp[i][j]=ans;
return dp[i][j];
}
int main()
{
long tst=1;
while(cin>>n>>m)
{
memset(dp,-1,sizeof(dp));
long i,p;
if(n==0&&m==0)break;
REP(i,n)
cin>>s[i];
REP(i,m)
cin>>s1[i];
cout<<"Twin Towers #"<<tst++<<endl;
cout<<"Number of Tiles : "<<call(0,0)<<endl;
cout<<endl;
}
return 0;
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন