-
Notifications
You must be signed in to change notification settings - Fork 0
/
uva10066.txt~
54 lines (52 loc) · 1.37 KB
/
uva10066.txt~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<map>
#define pi acos(0.0)
#define maxi 1010
using namespace std;
int i,j,k,l,m,n,a,b,t,c[maxi][maxi],x[1010],y[1010];
void lcs_length()
{
for(i=1;i<=a;i++)
{
for(j=1;j<=b;j++)
{
if(x[i-1]==y[j-1])
{
c[i][j]=c[i-1][j-1]+1;
//printf(" %d ", c[i][j]);
}
else
{
c[i][j]=max(c[i-1][j],c[i][j-1]);
//printf(" %d ", c[i][j]);
}
}
}
printf("Number of Tiles : %d\n", c[a][b]);
printf("\n");
}
int main()
{
int count=0;
memset(c,0,sizeof(c));
while(scanf("%d %d", &a,&b)==2&&(a!=0&&b!=0))
{
count++;
for(t=0;t<a;t++)
{
scanf("%d", &x[t]);
}
for(n=0;n<b;n++)
{
scanf("%d", &y[n]);
}
printf("Twin Towers #%d\n", count);
lcs_length();
}
}