forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
10066.cpp
59 lines (53 loc) · 846 Bytes
/
10066.cpp
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
54
55
56
57
58
59
#include <bits/stdc++.h>
using namespace std;
const int MAXSIZE = 100;
int N1, N2;
int T1[MAXSIZE + 1], T2[MAXSIZE + 1];
int lcs[MAXSIZE + 1][MAXSIZE + 1];
void input()
{
for (int i = 1; i <= N1; i++)
{
scanf("%d", T1 + i);
}
for (int i = 1; i <= N2; i++)
{
scanf("%d", T2 + i);
}
}
void solve(int kase)
{
int i, j;
for (i = 0; i <= N1; i++)
{
lcs[i][0] = 0;
}
for (j = 0; j <= N2; j++)
{
lcs[0][j] = 0;
}
for (i = 1; i <= N1; i++)
for (j = 1; j <= N2; j++)
{
if (T1[i] == T2[j])
{
lcs[i][j] = lcs[i - 1][j - 1] + 1;
}
else
{
lcs[i][j] = max(lcs[i - 1][j], lcs[i][j - 1]);
}
}
printf("Twin Towers #%d\n", kase);
printf("Number of Tiles : %d\n\n", lcs[N1][N2]);
}
int main()
{
int kase = 0;
while (EOF != scanf("%d%d", &N1, &N2) && N1)
{
input();
solve(++kase);
}
return 0;
}