Leetcode 714. 买卖股票的最佳时机含手续费(DAY 27) ---- 动态规划学习期
发布日期:2021-06-30 22:24:39
浏览次数:3
分类:技术文章
本文共 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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
做的很好,不错不错
[***.243.131.199]2024年04月22日 13时38分43秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Python一键获取微信推送封面图
2019-04-30
油猴脚本:微信推送浏览功能拓展
2019-04-30
JavaScript 表单操作与MD5加密
2019-04-30
JAVA学习笔记6 - 数组
2019-04-30
JAVA学习笔记9 - 异常
2019-04-30
JAVA学习笔记10 - 继承
2019-04-30
Android 开发学习笔记 00 - Getting Started
2019-04-30
【学习笔记】Android Activity
2019-04-30
Android使用Retrofit_00_Getting Started
2019-04-30
Android使用Retrofit_01_OAuth2 + GitHub
2019-04-30
【转载】将Ubuntu16.04 中gedit在仅显示一个文件时显示文件名tab
2019-04-30
调试 LenaCV 3D Camera (Linux)
2019-04-30
OpenCV杂记 - Mat in C++
2019-04-30
location区段
2019-04-30
nginx访问控制、基于用户认证、https配置
2019-04-30
SaltStack
2019-04-30
linux内存的寻址方式
2019-04-30
how2heap-double free
2019-04-30