本文共 1146 字,大约阅读时间需要 3 分钟。
题目解析:
注意只能够买一次和卖一次股票 其实这个题目就是最大子列和的变形,他是求的矩阵【23,24,27,18,23,19,31】这样的一个矩阵的最大利润,当有些天的利润为负值,则另begin移到这一天作为开始,这与最大子列和的思想完全相同。 可参考我的最大子列和程序// Author : yqtao// Date : 2016-6.19// Email :yqtao@whu.edu.cn/************************************************************************************ Say you have an array for which the ith element is the price of a given stock on day i.** If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),* design an algorithm to find the maximum profit.***********************************************************************************/#include "stdafx.h"#include#include #include #include
转载地址:http://psdoi.baihongyu.com/