📜  查找 lasgerst 独立集合数组的权重 - 无论代码示例

📅  最后修改于: 2022-03-11 14:59:04.252000             🧑  作者: Mango

代码示例1
def max_independant_weight(weights):
    def with_and_without(i):
        if i >= len(weights):
            return 0, 0
        left  = with_and_without(2*i + 1)
        right = with_and_without(2*i + 2)
        return (weights[i] + left[1] + right[1],
                max(left) + max(right))
    return max(with_and_without(0))