-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy path10066.cpp
43 lines (33 loc) · 831 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
#include <iostream>
using namespace std;
int main(void) {
int n1, n2;
int counter = 0;
int towers[2][101];
int dp[101][101];
while (cin >> n1 >> n2) {
if (n1 == 0 && n2 == 0)
break;
counter++;
for (int i = 0; i <= n1; i++)
dp[i][0] = 0;
for (int j = 0; j <= n2; j++)
dp[0][j] = 0;
for (int i = 0; i < n1; i++)
cin >> towers[0][i];
for (int i = 0; i < n2; i++)
cin >> towers[1][i];
for (int i = 1; i <= n1; i++) {
for (int j = 1; j <= n2; j++) {
if (towers[0][i-1] == towers[1][j-1])
dp[i][j] = dp[i-1][j-1] + 1;
else
dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
}
}
cout << "Twin Towers #" << counter << endl;
cout << "Number of Tiles : " << dp[n1][n2] << endl;
cout << endl;
}
return 0;
}