原题地址Best Time to Buy and Sell Stock III(参见这篇文章)的简化版迭代法求最大利润。当然是在峰值卖出,在低谷买进利润最大了。所以从后向前遍历所有价格,如果当前价格比之前的峰值价格还高,更新峰值价格,否则就用峰值价格减去当前价格看看利润多少。代码: 1 int ma...
分类:
其他好文 时间:
2015-01-30 17:22:44
阅读次数:
125
原题地址如果不限交易次数,把所有递增序列差值求和即可。代码: 1 int maxProfit(vector &prices) { 2 if (prices.empty()) 3 return 0; 4 5 int profi...
分类:
其他好文 时间:
2015-01-30 16:54:46
阅读次数:
129
Say you have an array for which the ith element isthe price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete as manytransactions as you like (ie, buy one an...
分类:
其他好文 时间:
2015-01-30 09:11:13
阅读次数:
176
Good Luck in CET-4 Everybody!
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5815 Accepted Submission(s): 3759
Problem Description...
分类:
其他好文 时间:
2015-01-30 09:05:09
阅读次数:
172
Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete at most two transactions.
注意
You may n...
分类:
其他好文 时间:
2015-01-28 14:47:27
阅读次数:
197
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/43155725
Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete as many tr...
分类:
其他好文 时间:
2015-01-26 22:57:31
阅读次数:
180
Crazy Shopping(拓扑排序+完全背包)Because of the 90th anniversary of theCoherent & Cute Patchouli(C.C.P),Kawashiro Nitoridecides to buy a lot of rare things to...
分类:
编程语言 时间:
2015-01-26 20:57:38
阅读次数:
220
Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete at most two transactions. Note: You may not eng...
分类:
编程语言 时间:
2015-01-26 13:45:27
阅读次数:
200
题意就是 给出一段插入,求出最后的序列。
做到n*logn基本都能过。
我用线段树做的。不过开始没想到怎么解决插入顺序问题,只知道存一个数组表示当前可以插入几个数。
后来ACdream群给了解答。每次update的时候,如果left的插入数大于插入就继续,否者就走right,并且将插入改为插入-left的插入数。
//PS 其实,觉得SBT应该能做的。
#include
...
分类:
其他好文 时间:
2015-01-26 13:45:03
阅读次数:
177
https://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/Say you have an array for which theithelement is the price of a given stock on da...
分类:
其他好文 时间:
2015-01-25 22:12:13
阅读次数:
201