标签:for 复杂 def 复杂度 sub this range += 最大子列和
#复杂度为n平方 ThisSum+=A[j]
if ThisSum>MaxSum:
MaxSum=ThisSum
print( MaxSum)
A=[ -2, 11, -4, 13, -5, -2 ]
N=len(A)
t= MaxSubseqSum1(A , N )
#复杂度更低 n 在线处理
def MaxSubseqSum1(A , N ):
ThisSum=0
MaxSum = 0
for i in range(0,N):
ThisSum+=A[i]
if ThisSum>MaxSum:
MaxSum=ThisSum
elif ThisSum<0:
ThisSum=0
print( MaxSum)
A=[ -1, 3, -2, 4, -6, 1,6,-1 ]
N=len(A)
t= MaxSubseqSum1(A , N )
标签:for 复杂 def 复杂度 sub this range += 最大子列和
原文地址:https://blog.51cto.com/13930723/2362589