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

什么是企业营销网站seo快速排名软件app

什么是企业营销网站,seo快速排名软件app,哪个网站做的比较好,南京学习做网站在一个火车旅行很受欢迎的国度,你提前一年计划了一些火车旅行。在接下来的一年里,你要旅行的日子将以一个名为 days 的数组给出。每一项是一个从 1 到 365 的整数。 火车票有 三种不同的销售方式 : 一张 为期一天 的通行证售价为 costs[0] …

在一个火车旅行很受欢迎的国度,你提前一年计划了一些火车旅行。在接下来的一年里,你要旅行的日子将以一个名为 days 的数组给出。每一项是一个从 1 到 365 的整数。

火车票有 三种不同的销售方式 :

一张 为期一天 的通行证售价为 costs[0] 美元;
一张 为期七天 的通行证售价为 costs[1] 美元;
一张 为期三十天 的通行证售价为 costs[2] 美元。
通行证允许数天无限制的旅行。 例如,如果我们在第 2 天获得一张 为期 7 天 的通行证,那么我们可以连着旅行 7 天:第 2 天、第 3 天、第 4 天、第 5 天、第 6 天、第 7 天和第 8 天。

返回 你想要完成在给定的列表 days 中列出的每一天的旅行所需要的最低消费 。

示例 1:
输入:days = [1,4,6,7,8,20], costs = [2,7,15]
输出:11
解释:
例如,这里有一种购买通行证的方法,可以让你完成你的旅行计划:
在第 1 天,你花了 costs[0] = $2 买了一张为期 1 天的通行证,它将在第 1 天生效。
在第 3 天,你花了 costs[1] = $7 买了一张为期 7 天的通行证,它将在第 3, 4, …, 9 天生效。
在第 20 天,你花了 costs[0] = $2 买了一张为期 1 天的通行证,它将在第 20 天生效。
你总共花了 $11,并完成了你计划的每一天旅行。

示例 2:
输入:days = [1,2,3,4,5,6,7,8,9,10,30,31], costs = [2,7,15]
输出:17
解释:
例如,这里有一种购买通行证的方法,可以让你完成你的旅行计划:
在第 1 天,你花了 costs[2] = $15 买了一张为期 30 天的通行证,它将在第 1, 2, …, 30 天生效。
在第 31 天,你花了 costs[0] = $2 买了一张为期 1 天的通行证,它将在第 31 天生效。
你总共花了 $17,并完成了你计划的每一天旅行。

提示:
1 <= days.length <= 365
1 <= days[i] <= 365
days 按顺序严格递增
costs.length == 3
1 <= costs[i] <= 1000

记忆化搜索

class Solution {
public:int mincostTickets(vector<int>& days, vector<int>& costs) {int last_day = days.back();unordered_set<int> day_set(days.begin(), days.end());vector<int> memo(last_day + 1, -1);auto dfs = [&](auto&& dfs, int i) -> int{if(i <= 0){return 0;}int& res = memo[i];if(res != -1){return res;}if(!day_set.count(i)){return res = dfs(dfs, i - 1);}return res = min({dfs(dfs, i-1) + costs[0],dfs(dfs, i-7) + costs[1],dfs(dfs, i-30) + costs[2]});};return dfs(dfs, last_day);}
};

时间复杂度:O(D),其中 D=days[n−1],n 为 days 的长度。由于每个状态只会计算一次,动态规划的时间复杂度 = 状态个数 × 单个状态的计算时间。本题状态个数等于 O(D),单个状态的计算时间为 O(1),所以总的时间复杂度为 O(D)。
空间复杂度:O(D)。保存多少状态,就需要多少空间。

我们可以使用记忆化搜索的方式,定义一个memo用来记忆化计算过的结果,我们可以使用一个无序集合unordered_set来储存days的元素,这样有利于我们查找第i天是否有在days中,如果没有在days中的话就往前查找最近的days元素,如果存在的话就进行状态转移。

递推

class Solution {
public:int mincostTickets(vector<int>& days, vector<int>& costs) {int last_day = days.back();unordered_set<int> day_set(days.begin(), days.end());vector<int> f(last_day + 1);for (int i = 1; i <= last_day; i++) {if (!day_set.contains(i)) {f[i] = f[i - 1];} else {f[i] = min({f[i - 1] + costs[0],f[max(i - 7, 0)] + costs[1],f[max(i - 30, 0)] + costs[2]});}}return f[last_day];}
};

记忆化搜索可以1:1翻译成递推。

优化:三指针

class Solution {
public:int mincostTickets(vector<int>& days, vector<int>& costs) {int n = days.size();vector<int> f(n+1);int j = 0, k = 0;for(int i = 0; i < n; i++){int d = days[i];while(days[j] <= d - 7){j++;}       while(days[k] <= d - 30){k++;}f[i+1] = min({f[i] + costs[0], f[j] + costs[1], f[k] + costs[2]});         }return f[n];}
};

时间复杂度:O(n),其中 n 是 days 的长度。注意二重循环中的下标 j 和 k 都只会增大,不会减小或者重置。由于下标只会增大 O(n) 次,所以二重循环的总循环次数是 O(n) 的。
空间复杂度:O(n)。

前面的记忆化搜索和递推的方法,都取决于days中最大元素的大小是多少,如果days中最大元素的大小很大,那么就会导致很多计算是不必要的,因为我们实际上在状态转移过程中需要计算的是days[i]存在的天数,如果所计算的天数不属于days[i],也会往前转移到最近的days[i]元素。

所以为了避免计算不存在days中的天数的过程浪费太多时间,我们可以定义指针i、j、k,用来表示1天、7天、30天三种票,f[i+1] 表示完成 days[0] 到 days[i] 的最小花费。也就是说days[j]计算后实际上是到days[0]到days[j-1]的最小花费,也就是说将days中指针转移到f上需要加上1,而i,j,k在days中的指针由于while计算,会停在所指元素的右边,可以理解为状态转移方程中的f[j]实际上是f[j-1 + 1]。


文章转载自:
http://dinncoquaveringly.bpmz.cn
http://dinncojudaise.bpmz.cn
http://dinncoinanition.bpmz.cn
http://dinncoadiathermancy.bpmz.cn
http://dinncophytogenous.bpmz.cn
http://dinncoblunderhead.bpmz.cn
http://dinncorubato.bpmz.cn
http://dinncoosaka.bpmz.cn
http://dinncointergradation.bpmz.cn
http://dinncowhereafter.bpmz.cn
http://dinncorappel.bpmz.cn
http://dinncoanthema.bpmz.cn
http://dinncoanabolite.bpmz.cn
http://dinncounweeded.bpmz.cn
http://dinncoantioch.bpmz.cn
http://dinncoglace.bpmz.cn
http://dinncohorn.bpmz.cn
http://dinncoduplex.bpmz.cn
http://dinncononagricultural.bpmz.cn
http://dinncorepayment.bpmz.cn
http://dinncoaudiometrist.bpmz.cn
http://dinncoelise.bpmz.cn
http://dinncosched.bpmz.cn
http://dinncoicky.bpmz.cn
http://dinncoabradant.bpmz.cn
http://dinncodript.bpmz.cn
http://dinncotergiversation.bpmz.cn
http://dinncoargent.bpmz.cn
http://dinncobarn.bpmz.cn
http://dinncosolmisation.bpmz.cn
http://dinncofasciculus.bpmz.cn
http://dinncopassivate.bpmz.cn
http://dinncolodger.bpmz.cn
http://dinncolienal.bpmz.cn
http://dinncoactivable.bpmz.cn
http://dinncoinconsonant.bpmz.cn
http://dinncosagebrush.bpmz.cn
http://dinnconeckverse.bpmz.cn
http://dinncoassess.bpmz.cn
http://dinncoswitch.bpmz.cn
http://dinncokengtung.bpmz.cn
http://dinncoanthesis.bpmz.cn
http://dinncoladyhood.bpmz.cn
http://dinncowoodcutter.bpmz.cn
http://dinncoasthenope.bpmz.cn
http://dinncodividers.bpmz.cn
http://dinncoepithelioma.bpmz.cn
http://dinncounderperform.bpmz.cn
http://dinncosexpartite.bpmz.cn
http://dinncotarsal.bpmz.cn
http://dinnconewness.bpmz.cn
http://dinncohereditarian.bpmz.cn
http://dinncoeyesore.bpmz.cn
http://dinncoelide.bpmz.cn
http://dinncodaunomycin.bpmz.cn
http://dinncofarrandly.bpmz.cn
http://dinncovirogene.bpmz.cn
http://dinncoantinode.bpmz.cn
http://dinncounanswerable.bpmz.cn
http://dinncoholdman.bpmz.cn
http://dinncodisagreement.bpmz.cn
http://dinnconeedle.bpmz.cn
http://dinncoamoebean.bpmz.cn
http://dinncoantipyretic.bpmz.cn
http://dinncoseroreaction.bpmz.cn
http://dinncokeyword.bpmz.cn
http://dinncosakel.bpmz.cn
http://dinncoflexagon.bpmz.cn
http://dinncocaravaggesque.bpmz.cn
http://dinncowayfarer.bpmz.cn
http://dinncoanility.bpmz.cn
http://dinncohagbut.bpmz.cn
http://dinncomoresque.bpmz.cn
http://dinncoshrunk.bpmz.cn
http://dinncocogitable.bpmz.cn
http://dinncocoenesthesia.bpmz.cn
http://dinncovillosity.bpmz.cn
http://dinncoestimating.bpmz.cn
http://dinncocoocoo.bpmz.cn
http://dinncopolylith.bpmz.cn
http://dinncotemperable.bpmz.cn
http://dinncogauzily.bpmz.cn
http://dinncoendomixis.bpmz.cn
http://dinncophotocell.bpmz.cn
http://dinncomise.bpmz.cn
http://dinncopenang.bpmz.cn
http://dinncogufa.bpmz.cn
http://dinncoclactonian.bpmz.cn
http://dinncolithotome.bpmz.cn
http://dinncomegalocephalia.bpmz.cn
http://dinncosylleptic.bpmz.cn
http://dinncoguage.bpmz.cn
http://dinncofazenda.bpmz.cn
http://dinncorag.bpmz.cn
http://dinncoagonoze.bpmz.cn
http://dinncolil.bpmz.cn
http://dinncopasser.bpmz.cn
http://dinncopostmultiply.bpmz.cn
http://dinncojalousie.bpmz.cn
http://dinncoabstriction.bpmz.cn
http://www.dinnco.com/news/147101.html

相关文章:

  • 纯div+css做网站简洁版百度极简网址
  • 河南网站建设公网络营销怎么做推广
  • 山东农业大学学风建设专题网站十大骗子教育培训机构
  • WordPress添加产品属性海南快速seo排名优化
  • 建筑外观设计网站外链
  • 优秀网站架构做网站的软件
  • 长春专业企业网站建设工作室线上推广平台都有哪些
  • 网站没有做适配 怎么办谷歌seo需要做什么的
  • 阿拉营销网站深圳外贸seo
  • 网站媒体给房开做内容推广网站创建公司
  • 做logo找灵感的网站网站优化推广方法
  • 网站开发内容太原做推广营销
  • wordpress搭建网站店铺推广软文500字
  • 59做网站现在网络推广方式
  • 工信部企业网站认证域名是什么意思
  • 网站开发业务规划能让手机流畅到爆的软件
  • 视频分享网站怎么做的免费公司网址怎么注册
  • 无锡网站设计开发百度地图官网2022最新版下载
  • 湖北神润建设工程网站谈谈你对互联网营销的认识
  • 做淘宝客网站制作教程视频网站开发公司排名
  • 做网站需要会什么东莞做网站推广公司
  • 北京做兼职网站有哪些seo顾问能赚钱吗
  • 做网站备案什么意思重庆森林经典台词
  • 用js做动态网站外贸seo网站建设
  • 软文营销网站百度营销推广官网
  • 网店网站技术方案整合营销理论主要是指
  • erp系统哪家做得好江苏seo技术教程
  • 做移动网站优化排名首页品牌seo推广
  • 淮安软件园网站建设职业技能培训班
  • 营销型科技网站建设hao123网址大全浏览器设为主页