-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlcs3.py
More file actions
23 lines (19 loc) · 775 Bytes
/
Copy pathlcs3.py
File metadata and controls
23 lines (19 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def long_common_sub(X, Y, Z, m, n, o):
L = [[[0 for i in range(o+1)] for j in range(n+1)] for k in range(m+1)]
for i in range(m+1):
for j in range(n+1):
for k in range(o+1):
if (i == 0 or j == 0 or k == 0):
L[i][j][k] = 0
elif (X[i-1] == Y[j-1] == Z[k-1]):
L[i][j][k] = L[i-1][j-1][k-1] + 1
else:
L[i][j][k] = max(L[i-1][j][k], L[i][j-1][k], L[i][j][k-1])
return L[m][n][o]
m = int(input())
a1 = [int(x) for x in input().split()][:m]
n = int(input())
a2 = [int(x) for x in input().split()][:n]
o = int(input())
a3 = [int(x) for x in input().split()][:o]
print(long_common_sub(a1, a2, a3, m, n, o))