Leetcode 714. 买卖股票的最佳时机含手续费(DAY 27) ---- 动态规划学习期
发布日期:2021-06-30 22:24:39
浏览次数:2
分类:技术文章
本文共 1017 字,大约阅读时间需要 3 分钟。
文章目录
原题题目
代码实现(首刷超暴力解法)超时
int profit;void calculateprofit(int* prices,int pricesSize,int pos,int shares,int fee,int money){ if(money > profit) profit = money; if(pos < pricesSize) { if(!shares) calculateprofit(prices,pricesSize,pos+1,prices[pos],fee,money-prices[pos]); else calculateprofit(prices,pricesSize,pos+1,0,fee,money+prices[pos]-fee); calculateprofit(prices,pricesSize,pos+1,shares,fee,money); }}int maxProfit(int* prices, int pricesSize, int fee){ profit = 0; calculateprofit(prices,pricesSize,0,0,fee,0); return profit;}
代码实现(半看解半自解) DP果然不好学
int maxProfit(int* prices, int pricesSize, int fee){ int dp[pricesSize][2],profit = 0,i; dp[0][0] = 0,dp[0][1] = (-prices[0]); for(i=1;i
代码实现(二刷自解 C++)
class Solution { public: int maxProfit(vector & prices, int fee) { int size = prices.size(); int prebuy = -prices[0],presold = 0,nowbuy = 0,nowsold = 0; for(int i=1;i
转载地址:https://love6.blog.csdn.net/article/details/112862173 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
不错!
[***.144.177.141]2024年04月23日 07时25分02秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
ACM 2017 北京区域赛 J-Pangu and Stones(区间dp)
2021-07-03
HDU - 5643 King's Game (约瑟夫环变式)
2021-07-03
UVA - 1452 Jump (约瑟夫环变式)
2021-07-03
POJ - 3517 And Then There Was One (约瑟夫环变式)
2021-07-03
HDU - 2068 RPG的错排 (错排+组合数)
2021-07-03
CodeForces 591C Median Smoothing(思维 模拟)
2021-07-03
升级yosemite后java出错的解决
2021-07-03
mac || Linux 命令行下实现批量重命名
2021-07-03
java常用类 String面试题
2021-07-03
Windows10下的powershell美化教程
2021-07-03
利用ffmpeg合并音频和视频
2021-07-03
刷好老毛子系统进不了老毛子系统后台的解决办法
2019-04-30
Parallels Desktop 16 不能联网的解决办法
2019-04-30
SLAM中TUM数据集更改图片名字
2019-04-30
手把手教你--jquery chosen插件的使用和API(html下拉框美化)
2019-04-30
手把手教你--JAVA微信支付(H5支付)
2019-04-30
solr修改schema文件(solr修改配置文件)
2019-04-30