User Tools

Site Tools


files:python3:alphabet

Kattis: Prime Sieve

1)

Python3 Source

alphabet.py
# Modified from CLRS3e
def LCS(x,y):
    m, n = len(x), len(y)
    C = [[0] * (n + 1) for i in range(m+1)]
    for i in range(1, m+1):
        for j in range(1, n+1):
            if x[i-1] == y[j-1]:
                C[i][j] = C[i-1][j-1] + 1
            else:
                C[i][j] = max(C[i][j-1], C[i-1][j])
    return C[-1][-1]
 
a = list(input())
b = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', \
'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
 
al, bl = len(a), len(b)
print(26 - LCS(a, b))

Solution Explanation

Potential "gotchas"

Finding the Solution

1)
Note: This page is a stub.
files/python3/alphabet.txt · Last modified: 2018/09/14 16:32 by jguerin