该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
def findmid(a,left,right):
if(right==left):
besti=left
bestj=right
sum=a[left]
print("一个数",sum,besti,bestj)
return sum,besti,bestj
center=int((left+right)/2)
s1=0
lefts=0
s2=0
rights=0
cibest=0
cjbest=0
i=center
j=center+1
while(i>=left):
lefts+=a[i]
if(lefts>s1):
s1=lefts
cibest=i
i-=1
if(i==left):
cibest=i
j=center+1
while(j<=right):
rights+=a[j]
if(rights>s2):
s2=rights
cjbest=j
j+=1
if(j==right):
cjbest=j
crosssum=s1+s2
return crosssum,cibest,cjbest
def Maxsubsum(a,left,right):
sum=0
global count
if(right==left):
besti=left
bestj=right
sum=a[left]
print("一个数",sum,besti,bestj)
return sum,besti,bestj
else:
center=int((left+right)/2)
(crosssum,cibest,cjbest)=findmid(a,left,right)
(rightsum,ribest,rjbest)=Maxsubsum(a,center+1,right)
(leftsum,libest,ljbest)=Maxsubsum(a,left,center)
if(crosssum
sum=rightsum
print("在右",sum,ribest,rjbest)
return sum,ribest,rjbest
if(crosssum
sum=leftsum
print("在左",sum,libest,ljbest)
return sum,libest,ljbest
count+=1
sum=crosssum
print("在中间",sum,cibest,cjbest)
return sum,cibest,cjbest