1. 

/*
 * ACM Programming Contest
 * Problem: 10066 (The Twin Towers)
 * Status: Accepted
 * Language: ANSI C
 * Runtime: 0.004
 * Date: 2009-05-25 21:40:14
 * Author: Andreas Kunft
 */

#include <stdio.h>

#define MAX 101

int str1[MAX], str2[MAX];
int i, j, n1, n2, cmp[MAX][MAX];

int LCSlength() {
for (i = 1; i <= n1; i++)
cmp[i][0] = 0;
for (j = 0; j <= n2; j++)
cmp[0][j] = 0;

for (i = 1; i <= n1; i++)
for (j = 1; j <= n2; j++) {
if (str1[i - 1] == str2[j - 1]) {
cmp[i][j] = cmp[i - 1][j - 1] + 1;
} else if (cmp[i - 1][j] > cmp[i][j - 1]) {
cmp[i][j] = cmp[i - 1][j];
} else {
cmp[i][j] = cmp[i][j - 1];
}
}

return cmp[n1][n2];
}

int main() {
int count = 1;
while (scanf("%d %d", &n1, &n2) == 2) {
if (n1 == 0 && n2 == 0)
return 0;
for (i = 0; i < n1; i++)
scanf("%d", &str1[i]);
for (j = 0; j < n2; j++)
scanf("%d", &str2[j]);
printf("Twin Towers #%d\n", count++);
printf("Number of Tiles : %d\n\n", LCSlength());
}
return 0;
}