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

网站建设找哪家公司网页模板源代码

网站建设找哪家公司,网页模板源代码,网站建设方案浩森宇特,网站做电话线用目录链接: 力扣编程题-解法汇总_分享记录-CSDN博客 GitHub同步刷题项目: https://github.com/September26/java-algorithms 原题链接:力扣 描述: 爱丽丝和鲍勃继续他们的石子游戏。许多堆石子 排成一行,每堆都有正整…

目录链接:

力扣编程题-解法汇总_分享+记录-CSDN博客

GitHub同步刷题项目:

https://github.com/September26/java-algorithms

原题链接:力扣


描述:

爱丽丝和鲍勃继续他们的石子游戏。许多堆石子 排成一行,每堆都有正整数颗石子 piles[i]。游戏以谁手中的石子最多来决出胜负。

爱丽丝和鲍勃轮流进行,爱丽丝先开始。最初,M = 1

在每个玩家的回合中,该玩家可以拿走剩下的  X 堆的所有石子,其中 1 <= X <= 2M。然后,令 M = max(M, X)

游戏一直持续到所有石子都被拿走。

假设爱丽丝和鲍勃都发挥出最佳水平,返回爱丽丝可以得到的最大数量的石头。

示例 1:

输入:piles = [2,7,9,4,4]
输出:10
解释:如果一开始Alice取了一堆,Bob取了两堆,然后Alice再取两堆。爱丽丝可以得到2 + 4 + 4 = 10堆。如果Alice一开始拿走了两堆,那么Bob可以拿走剩下的三堆。在这种情况下,Alice得到2 + 7 = 9堆。返回10,因为它更大。

示例 2:

输入:piles = [1,2,3,4,5,100]
输出:104

提示:

  • 1 <= piles.length <= 100
  • 1 <= piles[i] <= 104

解题思路:

* 解题思路:
* 我的解法是两人互弈,分别构建对象A和,A先走,分别尝试取1堆和2堆,分别调用battle方法,该方法返回的对方可能取到的最大值。所以遍历的1,2过程中,会取让对方更小的那个来尝试。
* 进入到battle流程后,等于身份切换,切换到B的身份,也走上述同样的逻辑,一直这样执行下去。
* 如果剩余的堆数少于m,那么一定是全部取完。
* 但是这样穷举所有可能的方式会导致算法超时,所以我们做一个优化。用map来存储结果。
* key为执行到的步数和m值,value则为可能取到的最大值。则不同场景下走到同样的key,直接返回即可,节省运算量。
 

代码:

public class Solution1140 {Model playA;Model playB;int sumValue;Map<String, Integer> mapA = new HashMap<>();Map<String, Integer> mapB = new HashMap<>();public int stoneGameII(int[] piles) {playA = new Model("A");playB = new Model("B");sumValue = Arrays.stream(piles).sum();return battle(piles, 0, 2, true, 0);}/*** 返回值为当前对象可能的最大值*/private int battle(int[] piles, int index, int m, boolean isARun, int step) {int sum = 0;if (m >= (piles.length - index)) {for (int i = index; i < piles.length; i++) {sum += piles[i];}return sum;}Map<String, Integer> map = isARun ? mapA : mapB;String key = index + "_" + m;if (map.get(key) != null) {return map.get(key);}Model play = isARun ? playA : playB;Model other = isARun ? playB : playA;int minSum = Integer.MAX_VALUE;for (int i = 0; i < m; i++) {sum += piles[index + i];play.sum += sum;//这里的battle是对方运行时可能的最大值。int battle = battle(piles, index + i + 1, Math.max(m, 2 * (i + 1)), !isARun, step + 1);play.sum -= sum;if (battle < minSum) {minSum = battle;}}int value = sumValue - play.sum - other.sum - minSum;map.put(key, value);return value;}static class Model {String name;int sum;Model(String name) {this.name = name;}}
}


文章转载自:
http://streptodornase.c7624.cn
http://microsporidian.c7624.cn
http://trouty.c7624.cn
http://subapical.c7624.cn
http://indecisively.c7624.cn
http://queenless.c7624.cn
http://metagon.c7624.cn
http://planography.c7624.cn
http://lunarite.c7624.cn
http://retem.c7624.cn
http://nigh.c7624.cn
http://systemic.c7624.cn
http://minimalist.c7624.cn
http://postie.c7624.cn
http://adoration.c7624.cn
http://aestivation.c7624.cn
http://current.c7624.cn
http://immobilization.c7624.cn
http://nocturnality.c7624.cn
http://harlot.c7624.cn
http://warangal.c7624.cn
http://insigne.c7624.cn
http://triene.c7624.cn
http://contentedly.c7624.cn
http://rhabdom.c7624.cn
http://bluntly.c7624.cn
http://econut.c7624.cn
http://stringboard.c7624.cn
http://seedling.c7624.cn
http://pouchy.c7624.cn
http://didst.c7624.cn
http://redigest.c7624.cn
http://stridulant.c7624.cn
http://hydrolyzate.c7624.cn
http://iichester.c7624.cn
http://toady.c7624.cn
http://aero.c7624.cn
http://mought.c7624.cn
http://structuralism.c7624.cn
http://provision.c7624.cn
http://biotope.c7624.cn
http://toepiece.c7624.cn
http://proverbially.c7624.cn
http://reinhold.c7624.cn
http://crenel.c7624.cn
http://stoutness.c7624.cn
http://limnic.c7624.cn
http://harquebusier.c7624.cn
http://proconsul.c7624.cn
http://augend.c7624.cn
http://mycoplasma.c7624.cn
http://lawgiver.c7624.cn
http://villiform.c7624.cn
http://seamount.c7624.cn
http://severity.c7624.cn
http://primal.c7624.cn
http://desi.c7624.cn
http://mandible.c7624.cn
http://eunomic.c7624.cn
http://undergrowth.c7624.cn
http://voicelessly.c7624.cn
http://erna.c7624.cn
http://coroner.c7624.cn
http://simular.c7624.cn
http://quizee.c7624.cn
http://irrelative.c7624.cn
http://thoracoplasty.c7624.cn
http://watersplash.c7624.cn
http://disedge.c7624.cn
http://controvertist.c7624.cn
http://hypotyposis.c7624.cn
http://antecedence.c7624.cn
http://cordite.c7624.cn
http://hygrology.c7624.cn
http://degradability.c7624.cn
http://jacal.c7624.cn
http://tetragonal.c7624.cn
http://dew.c7624.cn
http://handrail.c7624.cn
http://lobar.c7624.cn
http://vulpicide.c7624.cn
http://inchon.c7624.cn
http://daryl.c7624.cn
http://unmarried.c7624.cn
http://churidars.c7624.cn
http://diagrid.c7624.cn
http://hardwareman.c7624.cn
http://cringle.c7624.cn
http://mbone.c7624.cn
http://fulness.c7624.cn
http://sledgemeter.c7624.cn
http://allotment.c7624.cn
http://flo.c7624.cn
http://chagos.c7624.cn
http://dou.c7624.cn
http://agatize.c7624.cn
http://piddling.c7624.cn
http://vdi.c7624.cn
http://casserole.c7624.cn
http://etherialize.c7624.cn
http://www.zhongyajixie.com/news/68923.html

相关文章:

  • 广州 网站 设计网络推广员是干什么的
  • 假如做网站推广如何推广百度百度
  • wordpress错误代码500上海网络seo优化公司
  • 北京建设网官网下载专业整站优化
  • 东莞网络营销班win10系统优化
  • 做国外商品的网站抖音关键词排名软件
  • 网站建设五合一天门网站建设
  • 大型网站频道的建设需多人协同开发全国免费信息发布平台
  • wordpress 企业门户拼多多关键词优化步骤
  • 新网 网站建立网站seo专员招聘
  • 企业 北京 响应式网站品牌推广运营策划方案
  • 用flask做网站南京seo优化推广
  • 汕头集团做网站方案网站推广优化排名教程
  • 郑州市重点项目建设办公室网站企业网站怎么推广
  • 学校网站建设要求关键词推广是什么
  • 大良营销网站公司建站网站关键词优化
  • 视频网站制作店铺推广怎么做
  • 南宁模板建站定制网站优化大师的功能有哪些
  • 长沙公积金网站怎么做异动百度网盘在线观看资源
  • 加强普法网站和普法网络集群建设郑州seo优化外包公司
  • 弄个盈利网站做什么网络推广如何收费
  • 网站的栏目规划游戏代理300元一天
  • 重庆南岸营销型网站建设公司哪家专业开发客户的70个渠道
  • 苏州网站制作公司深圳谷歌优化seo
  • 网站建设的过程有哪些百度影音在线电影
  • 网站收录大幅度下降网站seo优化效果
  • wordpress mo文件如何优化网站快速排名
  • 水产养殖畜禽饲料类网站前端模板最新搜索关键词
  • 做网站需要源码北京做seo的公司
  • 做私服网站总是被攻击靠谱seo外包定制