"""Author : YvonneThis is a pure Python implementation of Dynamic Programming solution to thelongest_sub_array problem.The problem is :Given an array, to find the longest and continuous sub array and get the max sum of thesub array in the given array."""class SubArray:def __init__(self, arr):# we need a list not a string, so do something to change the typeself.array = arr.split(",")print(("the input array is:", self.array))def solve_sub_array(self):rear = [int(self.array[0])] * len(self.array)sum_value = [int(self.array[0])] * len(self.array)for i in range(1, len(self.array)):sum_value[i] = max(int(self.array[i]) + sum_value[i - 1], int(self.array[i]))rear[i] = max(sum_value[i], rear[i - 1])return rear[len(self.array) - 1]if __name__ == "__main__":whole_array = input("please input some numbers:")array = SubArray(whole_array)re = array.solve_sub_array()print(("the results is:", re))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。