经过和lz等本讨论帖等人的讨论,完善了下思路,对于长度相同的情况没必要去重,只需增加一个长度的判断,放python代码如下,欢迎纠错

import sys
line = sys.stdin.readline().strip()
while line:
    line = sys.stdin.readline().strip()
    L = list(map(int, line.split()))
    line = sys.stdin.readline().strip()
    W = list(map(int, line.split()))
    n = len(L)
    arr = [(l, w) for (l, w) in zip(L, W)]
    arr = sorted(arr, key=lambda x: x[0])

    ls, ws = [0] * n, [0] * n
    ls[0], ws[0] = 1, arr[0][1]
    for i in range(1, n):
        ls[i], ws[i] = ls[i - 1], ws[i - 1]
        for j in range(i):
            if arr[i][1] * 7 >= ws[j] and arr[j][0] < arr[i][0]:
                if ls[j] + 1 > ls[i]:
                    ls[i] = ls[j] + 1
                    ws[i] = ws[j] + arr[i][1]
                elif ls[j] + 1 == ls[i]:
                    ws[i] = min(ws[j] + arr[i][1], ls[i])
    print(ls[n - 1])
    line = sys.stdin.readline().strip()