python中最长的递增子序列Alphabet e

我现在正在通过最长的递增子序列练习Dp,现在我知道如何制作“正常”子序列了。但是,我想使使用字母有所不同。我想编写可找到字母字符串中LIS长度的代码。例如,如果我输入abcabc,则结果将为3(因为abc是字符串中唯一的子序列。)

这是我当前的代码版本 def LIS(A):

L = list()
for i in range(0, len(A)):
    L.append(list())

# the first increasing subsequence is the first element in A
L[0].append(A[0])

for i in range(1, len(A)):
    for j in range(0, i):

        # a new larger increasing subsequence found
        if (A[j] < A[i]) and (len(L[i]) < len(L[j])):
            'throw the previous list'
            L[i] = []
            'add all elements of L[j] to L[i]'
            L[i].extend(L[j])
    L[i].append(A[i])

for i in range(len(A)):
# print an increasing subsequence
    print (L[i])
A = input()
LIS(A)

我应该如何改变呢?

评论