309. Best Time to Buy and Sell Stock with Cooldown---C语言
来源:互联网 发布:软件测试职位 编辑:程序博客网 时间:2024/06/10 23:22
大概就是隔一天才能做交易
我看到网上有个大神是用自动机的知识,我觉得特别棒
原文链接http://www.cnblogs.com/jdneo/p/5228004.html
最后贴出我的代码
int max(int a,int b)
{
if(a>b)
return a;
else return b;
}
int maxProfit(int* prices, int pricesSize)
{
if (pricesSize <= 1) return 0;
int s0[pricesSize];
int s1[pricesSize];
int s2[pricesSize];
s1[0] = -prices[0];
s0[0] = 0;
s2[0] = 0;
for (int i = 1; i < pricesSize; i++) {
s0[i] = max(s0[i-1], s2[i - 1]);
s1[i] = max(s1[i-1], s0[i - 1] - prices[i]);
s2[i] = s1[i - 1] + prices[i];
}
return max(s0[pricesSize - 1], s2[pricesSize - 1]);
}
阅读全文
0 0
- 309. Best Time to Buy and Sell Stock with Cooldown---C语言
- 309.Best Time to Buy and Sell Stock with Cooldown
- 309. Best Time to Buy and Sell Stock with Cooldown
- 309. Best Time to Buy and Sell Stock with Cooldown
- 309. Best Time to Buy and Sell Stock with Cooldown
- 309. Best Time to Buy and Sell Stock with Cooldown
- 309. Best Time to Buy and Sell Stock with Cooldown
- 309. Best Time to Buy and Sell Stock with Cooldown
- 309. Best Time to Buy and Sell Stock with Cooldown
- 309. Best Time to Buy and Sell Stock with Cooldown
- 309. Best Time to Buy and Sell Stock with Cooldown
- 309. Best Time to Buy and Sell Stock with Cooldown
- 309. Best Time to Buy and Sell Stock with Cooldown
- 309. Best Time to Buy and Sell Stock with Cooldown
- 309. Best Time to Buy and Sell Stock with Cooldown
- 309. Best Time to Buy and Sell Stock with Cooldown
- 309. Best Time to Buy and Sell Stock with Cooldown
- 309. Best Time to Buy and Sell Stock with Cooldown
- GIF文件格式详解
- Android获得json和XML
- 算法第四版 练习 1.3.34
- AI将带我们去何方?(上-前言篇)
- WekaAPI的学习(加载数据)
- 309. Best Time to Buy and Sell Stock with Cooldown---C语言
- ThinkPHP简介
- C/C++典型漏洞产生原理与Demo
- JAVA购物管理系统
- HDU 6035 Colorful Tree (树形dp)
- 【南阳 oj 】6-- 喷水装置(一)(贪心算法)
- 访问修饰符private
- hdu 2008 数值统计
- opencv写入视频文件