标签:pytho 最大 div 分析 text post 版本号 span sum
简短的分析见:http://blog.csdn.net/shiquxinkong/article/details/17934747
def FindGreatestSumOfSubArray(array, index = None): curSum = 0 maxSum = 0 #return maxSum without the start and end index if index == None: for x in array: curSum = max(curSum, 0) curSum += x maxSum = max(maxSum, curSum) return maxSum #return maxSum and the start and end index else: curS = -1 curE = -1 maxS = -1 maxE = -1 for i in range(len(array)): if curSum <= 0: curSum = array[i] curS = i curE = i else: curSum += array[i] curE = i if curSum > maxSum: maxS = curS maxE = curE maxSum = curSum return maxSum, maxS, maxE
上面的代码尽管看起来不像动态规划,可是思想确实是dp的思想。
标签:pytho 最大 div 分析 text post 版本号 span sum
原文地址:http://www.cnblogs.com/mfmdaoyou/p/7079911.html