-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path111.cpp
More file actions
48 lines (37 loc) · 916 Bytes
/
111.cpp
File metadata and controls
48 lines (37 loc) · 916 Bytes
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
#include <bits/stdc++.h>
const int max = 25;
int x[max], y[max];
int c[max][max];
int lcs(int n, int m) {
int i, j, l;
for (i = 1; i <= n; i++) c[i][0] = 0;
for (j = 0; j <= m; j++) c[0][j] = 0;
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++) {
if (x[i - 1] == y[j - 1])
c[i][j] = c[i - 1][j - 1] + 1;
else if (c[i - 1][j] >= c[i][j - 1])
c[i][j] = c[i - 1][j];
else
c[i][j] = c[i][j - 1];
}
return c[n][m];
}
int main() {
int n, m, i, j, k, t;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &m);
x[m - 1] = i;
}
while (scanf("%d", &m) == 1) {
y[m - 1] = 1;
for (i = 2; i <= n; i++) {
scanf("%d", &m);
y[m - 1] = i;
}
i = lcs(n, n);
printf("%d\n", i);
}
return 0;
}