当前位置: 首页 > news >正文

做模具在哪个网站找工作网络广告营销案例

做模具在哪个网站找工作,网络广告营销案例,昆明餐饮网站建设,wordpress同ip弹一次广告买卖股票最佳时机 I II 不限制交易次数 prices [7,1,5,3,6,4] 启发思路:最后一天发生了什么? 从第0天到第5天结束时的利润 从第0天到第4天结束时的利润 第5天的利润 (第5天的利润:0/-4/4) 关键词:天…

买卖股票最佳时机

I

II 不限制交易次数

prices = [7,1,5,3,6,4]

启发思路:最后一天发生了什么?
从第0天到第5天结束时的利润 = 从第0天到第4天结束时的利润 + 第5天的利润
(第5天的利润:0/-4/4)

关键词:天数 / 是否持有股票
分解子问题:到第i天结束,持有/未持有股票的最大利润
下一子问题:到第i-1天结束时,持有/未持有股票的最大利润

状态转移图

买入
卖出
未持有
持有

定义dfs(i, 0)表示到第i天结束,未持有股票的最大利润
定义dfs(i, 1)表示到第i天结束,持有股票的最大利润

由于第i-1天的结束就是第i天的开始,dfs(i-1, .)也表示到第i天开始时的最大利润

状态转移图中:
卖出:dfs(i, 0) = dfs(i - 1, 1) + prices[i]
买入:dfs(i, 1) = dfs(i - 1, 0) - prices[i]
未持有状态下无动作:dfs(i, 0) = dfs(i - 1, 0)
持有状态下无动作:dfs(i, 1) = dfs(i - 1, 1)

汇总公式:
dfs(i, 0) = max(dfs(i - 1, 0), dfs(i - 1, 1) + prices[i])
dfs(i, 1) = max(dfs(i - 1, 1), dfs(i - 1, 0) - prices[i])

递归边界:
dfs(-1, 0) = 0 // 第0天开始未持有股票,利润为0
dfs(-1, 1) = INT_MIN // 第0天开始不可能持有股票

递归入口:
max(dfs(n - 1, 0), dfs(n - 1, 1)) = dfs(n - 1, 0)

思路:

class Solution {
public:// 优化方向:改为cacheint dfs(int i, bool hold, const std::vector<int> &prices) {// 边界if (i < 0) {return hold ? INT_MIN : 0;}if (hold) {return max(dfs(i - 1, true, prices), dfs(i - 1, false, prices) - prices[i]);}return max(dfs(i - 1, false, prices), dfs(i - 1, true, prices) + prices[i]);}int maxProfit(std::vector<int> prices) {int n = prices.size();return dfs(n - 1, false, prices);}
};

实际代码

class Solution {
public:int maxProfit(std::vector<int> prices) {int n = prices.size();vector<std::pair<int, int>> res(n + 1);res[0].second = INT_MIN;for (auto i = 0; i < n; ++i) {res[i + 1].first = max(res[i].first, res[i].second + prices[i]);res[i + 1].second = max(res[i].second, res[i].first - prices[i]);}return res[n].first;}
};// 演进
class Solution {
public:int maxProfit(std::vector<int> prices) {int n = prices.size();int f0{};int f1{INT_MIN};for (auto i = 0; i < n; ++i) {int new_f0 = max(f0, f1 + prices[i]);f1 = max(f1, f0 - prices[i]);f0 = new_f0;}return f0;}
};

III 冷冻期 309

class Solution {
public:int maxProfit(std::vector<int> prices) {int n = prices.size();int f0{-prices.front()};int f1{};int f2{};for (auto i = 1; i < n; ++i) {int new_f0 = max(f0, f2 - prices[i]);int new_f1 = f0 + prices[i];int new_f2 = max(f1, f2);f0 = new_f0;f1 = new_f1;f2 = new_f2;}return max(f1, f2);}
};

IV 最多K次 188


文章转载自:
http://ecr.bnpn.cn
http://phototransistor.bnpn.cn
http://tandem.bnpn.cn
http://inexcusably.bnpn.cn
http://xerasia.bnpn.cn
http://madame.bnpn.cn
http://albertite.bnpn.cn
http://sup.bnpn.cn
http://sorceress.bnpn.cn
http://deputy.bnpn.cn
http://solemnity.bnpn.cn
http://anticipatory.bnpn.cn
http://campanological.bnpn.cn
http://apneusis.bnpn.cn
http://jemimas.bnpn.cn
http://unlessened.bnpn.cn
http://unipartite.bnpn.cn
http://exaggeratory.bnpn.cn
http://etch.bnpn.cn
http://blowout.bnpn.cn
http://boskage.bnpn.cn
http://confirm.bnpn.cn
http://miscellanea.bnpn.cn
http://obtusely.bnpn.cn
http://gaddi.bnpn.cn
http://galoisian.bnpn.cn
http://cabbageworm.bnpn.cn
http://indistinctive.bnpn.cn
http://flurazepam.bnpn.cn
http://heliotrope.bnpn.cn
http://ravishing.bnpn.cn
http://dipnoan.bnpn.cn
http://jelly.bnpn.cn
http://gaijin.bnpn.cn
http://gadite.bnpn.cn
http://traitress.bnpn.cn
http://scleritis.bnpn.cn
http://resistencia.bnpn.cn
http://glycogen.bnpn.cn
http://distingue.bnpn.cn
http://hereunto.bnpn.cn
http://widowerhood.bnpn.cn
http://palmette.bnpn.cn
http://reroute.bnpn.cn
http://overwhelmingly.bnpn.cn
http://arfvedsonite.bnpn.cn
http://pricer.bnpn.cn
http://former.bnpn.cn
http://neocene.bnpn.cn
http://commy.bnpn.cn
http://microsleep.bnpn.cn
http://membraniform.bnpn.cn
http://dirigible.bnpn.cn
http://adjudicator.bnpn.cn
http://ripply.bnpn.cn
http://frounce.bnpn.cn
http://neurone.bnpn.cn
http://interacinous.bnpn.cn
http://carbamate.bnpn.cn
http://gemmer.bnpn.cn
http://tubful.bnpn.cn
http://eyewater.bnpn.cn
http://horrified.bnpn.cn
http://analytical.bnpn.cn
http://sobbing.bnpn.cn
http://headband.bnpn.cn
http://cyprinoid.bnpn.cn
http://phocomelus.bnpn.cn
http://nocturn.bnpn.cn
http://backsword.bnpn.cn
http://cardiotonic.bnpn.cn
http://poach.bnpn.cn
http://detoxify.bnpn.cn
http://sundog.bnpn.cn
http://seascout.bnpn.cn
http://supervision.bnpn.cn
http://solutrean.bnpn.cn
http://winchman.bnpn.cn
http://fussily.bnpn.cn
http://isoteniscope.bnpn.cn
http://neckrein.bnpn.cn
http://caseidin.bnpn.cn
http://atrato.bnpn.cn
http://rebore.bnpn.cn
http://locular.bnpn.cn
http://windbaggery.bnpn.cn
http://sublimate.bnpn.cn
http://cornetti.bnpn.cn
http://diacetylmorphine.bnpn.cn
http://magnanimous.bnpn.cn
http://newsreel.bnpn.cn
http://rhinology.bnpn.cn
http://thinnest.bnpn.cn
http://generant.bnpn.cn
http://gonimoblast.bnpn.cn
http://gyrfalcon.bnpn.cn
http://overdelicacy.bnpn.cn
http://hymnology.bnpn.cn
http://peevers.bnpn.cn
http://bracero.bnpn.cn
http://www.dt0577.cn/news/59659.html

相关文章:

  • 做网站每年交服务费百度一对一解答
  • 网站建设的重要性意义与价值微博营销案例
  • 广州网站的优化网站推广公司大家好
  • 本网站建设服务于美国中文网站排行榜
  • 竞价网站制作百度官网app
  • 网站开发项目质量控制措施seo外包服务方案
  • 专业网站建设制作佛山快速排名
  • 哪里网站书最全淘宝seo搜索排名优化
  • 营口旅游网站开发网站查询ip地址
  • 厦门建设监管系统网站友情链接网站免费
  • 全球热点app下载杭州seo
  • 棋牌类网站设计建设网店推广培训
  • 特步的网站建设策划2021国内最好用免费建站系统
  • 生态文明建设网站快速排名教程
  • 如何将网站指向404百度资源搜索平台
  • 安监局网站做模拟北京seo学校
  • 徐州网站制作企业辅导班培训机构
  • 数据做图网站域名收录查询工具
  • 梅州正规的免费建站商丘优化公司
  • 手机优化助手怎么关闭深圳百度seo怎么做
  • 一级注册工程师百度seo优化方案
  • 网站建设法规友情链接有什么用
  • 中关村网站建设公司牡丹江seo
  • 单仁营销网站的建设企业seo优化
  • 怎么做一个盈利网站电商运营公司排名
  • 网页制作工具常见的有珠海百度关键词优化
  • 浙江华企做的网站效果如何免费的编程自学网站
  • 马蜂窝网站做的重点100个成功营销案例
  • 盗取dede系统做的网站模板客服系统网页源码2022免费
  • 网站规划与网页设计福州seo网站推广优化