#include<iostream>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<queue>
using namespace std;
#define INF (1<<29)
#define SET(a) memset(a,-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define FILL(a,v) memset(a,v,sizeof(a))
#define PB push_back
#define FOR(i,n) for(int i = 0;i<n;i++)
#define PI acos(-1.0)
#define EPS 1e-9
#define MP(a,b) make_pair(a,b)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define LL long long
#define MX 100000
#define MOD 1000000007
int x[110],y[110],c[110][110];
int LCS(int m,int n)
{
for(int i=0;i<=m;i++)
c[i][0]=0;
for(int i=0;i<=n;i++)
c[0][i]=0;
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
if(x[i]==y[j])
c[i][j]=c[i-1][j-1]+1;
else
c[i][j]=max(c[i-1][j],c[i][j-1]);
return c[m][n];
}
main()
{
int n1,n2,kk=1;
while(cin>>n1>>n2)
{
if(n1==0 && n2==0)
break;
for(int i=1;i<=n1;i++)
cin>>x[i];
for(int i=1;i<=n2;i++)
cin>>y[i];
int res=LCS(n1,n2);
cout<<"Twin Towers #"<<kk++<<endl<<"Number of Tiles : ";
cout<<res<<endl<<endl;
}
}
No comments:
Post a Comment