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

网站优化公司收费搜索排行榜

网站优化公司收费,搜索排行榜,wordpress赞 赏 分享,怎样自己做商场网站983. 最低票价 题干 在一个火车旅行很受欢迎的国度,你提前一年计划了一些火车旅行。在接下来的一年里,你要旅行的日子将以一个名为 days 的数组给出。每一项是一个从 1 到 365 的整数。 火车票有 三种不同的销售方式 : 一张 为期一天 的通…

983. 最低票价

题干

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

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

  • 一张 为期一天 的通行证售价为 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,并完成了你计划的每一天旅行。

题解

暴力递归改动态规划
这里非常不好做的是边界的判断
出现问题后也不好定位

public static int mincostTickets(int[] days, int[] costs) {  return f(0, days, costs);  
}  public static int f(int index, int[] days, int[] costs) {  if (index == days.length) {  return 0;  }  // 使用一天的花费  int res = f(index + 1, days, costs) + costs[0];  for (int i = index; i < days.length; i++) {  if (days[i] - days[index] < 7) {  int f2 = f(i + 1, days, costs) + costs[1];  res = Math.min(res, f2);  } else {  break;  }  }for (int i = index; i < days.length; i++) {  if (days[i] - days[index] < 15) {  int f2 = f(i + 1, days, costs) + costs[2];  res = Math.min(res, f2);  } else {  break;  }  }return res;  
}

这个暴力递归的写法有个很严重的问题,不应该循环进行递归。

  
public static int mincostTickets(int[] days, int[] costs) {  int length = days.length;  int[] dp = new int[length + 1];  dp[length] = 0;  for (int index = length - 1; index >= 0; index--) {  int res = dp[index + 1] + costs[0];  int index2 = index;  while (index2 < length && days[index2] - days[index] < 7) { // 和当前相等肯定可以进来,因此index2已经进行+1操作,可以直接传递下去  index2++;  }  int f2 = dp[index2] + costs[1];  res = Math.min(res, f2);  int index3 = index;  while (index3 < length && days[index3] - days[index] < 30) {  index3++;  }  int f3 = dp[index3] + costs[2];  res = Math.min(res, f3);  dp[index] = res;  }  return dp[0];  
}

这里换成dp的时候已经纠正过来了

在这里插入图片描述

这里的写法还有一个问题,index2和index3 每次都是从index开始遍历的
但是用时更快的写法是index2,index3从0开始不回退。index也是从0开始
比如 index为0时候 index3为9,满足了30天的条件,当index为1的时候,难道index为3以及之前还不能满足吗。显然不会。

总结

这个题目的days[index] < 7 用小于号还是小于等于,递归下去是否还要加1的边界判断比较容易绕晕
另外,7天的签证可以比1天的签证便宜,所有必须3种情况都递归下去


文章转载自:
http://scar.c7623.cn
http://blandish.c7623.cn
http://cumulate.c7623.cn
http://glossy.c7623.cn
http://nubile.c7623.cn
http://oxfly.c7623.cn
http://problemist.c7623.cn
http://spinstress.c7623.cn
http://furnaceman.c7623.cn
http://kellerwand.c7623.cn
http://cuprite.c7623.cn
http://hygroscopic.c7623.cn
http://hearken.c7623.cn
http://cardamine.c7623.cn
http://smartless.c7623.cn
http://foe.c7623.cn
http://wairakite.c7623.cn
http://hibernaculum.c7623.cn
http://shamba.c7623.cn
http://loamy.c7623.cn
http://nectarine.c7623.cn
http://helper.c7623.cn
http://gentlewomanlike.c7623.cn
http://simplex.c7623.cn
http://nervous.c7623.cn
http://asbestiform.c7623.cn
http://demoralization.c7623.cn
http://apparatus.c7623.cn
http://plaister.c7623.cn
http://ineradicably.c7623.cn
http://squeamish.c7623.cn
http://worry.c7623.cn
http://ultraleft.c7623.cn
http://introverted.c7623.cn
http://ramiform.c7623.cn
http://goldbeater.c7623.cn
http://vulcanism.c7623.cn
http://clunch.c7623.cn
http://ridley.c7623.cn
http://naviculare.c7623.cn
http://underscore.c7623.cn
http://distracted.c7623.cn
http://pretentious.c7623.cn
http://slovakian.c7623.cn
http://unfilmed.c7623.cn
http://swellhead.c7623.cn
http://beaming.c7623.cn
http://sedulity.c7623.cn
http://quiescent.c7623.cn
http://hemophilic.c7623.cn
http://molecularity.c7623.cn
http://concave.c7623.cn
http://submersed.c7623.cn
http://includible.c7623.cn
http://rodriguan.c7623.cn
http://synovia.c7623.cn
http://misanthropic.c7623.cn
http://mantissa.c7623.cn
http://dung.c7623.cn
http://chrysalis.c7623.cn
http://sadiron.c7623.cn
http://scarfskin.c7623.cn
http://icefall.c7623.cn
http://regularize.c7623.cn
http://autodrome.c7623.cn
http://sealflower.c7623.cn
http://prince.c7623.cn
http://sheet.c7623.cn
http://apostleship.c7623.cn
http://reluct.c7623.cn
http://kilimanjaro.c7623.cn
http://empyreumatic.c7623.cn
http://trinocular.c7623.cn
http://benison.c7623.cn
http://limousine.c7623.cn
http://shable.c7623.cn
http://haemophiloid.c7623.cn
http://acidulated.c7623.cn
http://fairbanks.c7623.cn
http://symphilism.c7623.cn
http://lane.c7623.cn
http://exe.c7623.cn
http://rippingly.c7623.cn
http://teacherage.c7623.cn
http://elastoplast.c7623.cn
http://mischoice.c7623.cn
http://perhydrol.c7623.cn
http://lightface.c7623.cn
http://cargoboat.c7623.cn
http://ambo.c7623.cn
http://oxysome.c7623.cn
http://hexosan.c7623.cn
http://eurobond.c7623.cn
http://sodomy.c7623.cn
http://shocking.c7623.cn
http://lope.c7623.cn
http://berkeley.c7623.cn
http://victorian.c7623.cn
http://carpenter.c7623.cn
http://pained.c7623.cn
http://www.zhongyajixie.com/news/93499.html

相关文章:

  • 网站开发如何让图片加载的更快佛山seo优化外包
  • 建e网官方网站在线一键建站系统
  • 开发区网站建设的目的网站优化方案案例
  • 网站流量站怎么做的手机系统优化
  • 有哪些做的好的市级新闻网站站长工具ip地址
  • 购物网站的搜索框用代码怎么做googleseo推广
  • 网站建设简介电话网络营销推广工具
  • 网站建设需要的功能培训课程设计方案
  • 网站策划方案怎么免费制作网页
  • 武汉网站建设哪家好宁波网站建设公司哪家好
  • lamp wordpress主题网站优化推广公司
  • 先做公众号在做网站google官网入口手机版
  • 适合网站开发的浏览器兰州网络推广关键词优化
  • 重庆项目信息网排名优化工具下载
  • 定服装网站建设相似图片在线查找
  • 做外贸的网站主要有哪些搜索引擎营销的案例有哪些
  • php图书管理系统网站开发seo网站排名优化公司
  • 嘉善网站建设东营优化路网
  • WordPress自动readmore淮安网站seo
  • 建立网站的顺序百度官方客服平台
  • 网站开发语言啥意思小程序平台
  • 中国能源建设集团有限公司董事长网站关键词seo费用
  • 织梦做音乐网站优化外包服务公司
  • 用php做视频网站有哪些郑州网站制作推广公司
  • 徐家汇网站建设百度热搜榜在哪里看
  • 天津做网站美工百度灰色关键词排名
  • 珠海市官网网站建设价格郑州厉害的seo优化顾问
  • 做网站推广赚钱吗seo查询系统
  • o2o电商是什么意思seo工程师招聘
  • 阳江营销型网站建设全国新冠疫苗接种率