乘积最大子序列

def find_max_m(x):
    max_p = x[0]
    min_n = x[0]
    res = x[0]
    for i in range(1,len(x)):
        max_p = max(max_p*x[i],min_n*x[i],x[i])
        min_n = min(max_p*x[i],min_n*x[i],x[i])
        res = max(max_p,res)
    return res

x = [-2.5,3,3.3,0.1,20,21,0.00001,-0.1, 4, 0, 3, 0.5, 8, -1]
print(find_max_m(x))

动态规划

你可能感兴趣的:(算法基础)