diff options
author | Santo Cariotti <santo@dcariotti.me> | 2024-05-28 10:29:13 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2024-05-28 10:29:13 +0200 |
commit | f05d888a0b621ca4e99e2b0fb6e23c097006fe41 (patch) | |
tree | eebbb2489144112d3288393e354d19375a0aa088 /progs/a146.py |
Init
Diffstat (limited to 'progs/a146.py')
-rw-r--r-- | progs/a146.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/progs/a146.py b/progs/a146.py new file mode 100644 index 0000000..2db2801 --- /dev/null +++ b/progs/a146.py @@ -0,0 +1,16 @@ +def lcs_of_three(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] and
+ X[i-1] == Z[k-1]):
+ L[i][j][k] = L[i-1][j-1][k-1] + 1
+ else:
+ L[i][j][k] = max(max(L[i-1][j][k],
+ L[i][j-1][k]),
+ L[i][j][k-1])
+ return L[m][n][o]
\ No newline at end of file |