标签:append while logs 连续 不可 www 算法 lin .com
暴力求解不可取
或许可以从 O(n)复杂度内求解最大连续子数组的算法 得到灵感
代码
def getMaxSub(matrix):
sum = []
for line in matrix:
rowSum = []
s = 0
for i in line:
s += i
rowSum.append(s)
sum.append(rowSum)
m = len(matrix)
n = len(matrix[0])
max = matrix[0][0]
i = 0
j = 0
while(i<m):
while(j<n):
p = i
while(p<m):
q = j
while(q<n):
res = 0
for row in range(i,p+1):
if(i==0):
res += sum[row][q]
else:
res += (sum[row][q] - sum[row][i-1])
if(res<0): break
max = res if max<res else max
q += 1
p += 1
j += 1
i += 1
print(max)
标签:append while logs 连续 不可 www 算法 lin .com
原文地址:https://www.cnblogs.com/zxpnotebook/p/10097261.html