动态规划最大利润的问题
# 求解最优性的问题 # 线性动规 # 区域动归 a = [1, 3, 4, 5, 6, 2, 7] def foo(arr): if len(arr) <= 1: return 0 min_num = arr[0] max_num = 0 for item in arr: history = item - min_num # 历史利润最大的 max_num = max(max_num, history) min_num = min(min_num, item) return max_num, min_num if __name__ == '__main__': print(foo(a))