当前位置:网站首页>HDU1422 重温世界杯【DP】
HDU1422 重温世界杯【DP】
2022-07-27 12:59:00 【51CTO】
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1422
题目大意:
给你N个城市,参观路线为1~2~3~4~5~…~N~1。可以从任何一座城市开始参观。每座城市提供的
生活费和需要的花费都不同,问:最多能参观多少个城市。
思路:
因为能形成循环,所以在原有数据的后边再接上1~N的数据。然后用动态规划来做。状态为:当上一
个城市剩下的钱不为负(即还未结束旅游),如果上一个城市剩下的钱加上当前城市的钱大于当前的生活
费,那么dp[i] = dp[i-1] + 1,更新剩下的钱,如果不够旅游了,就将剩下的钱归为0,从当前点开始
旅游,计算最大的dp[i],得到的就是最多能参观的城市数。这里加一个优化,当dp[i] == N(即参观完
N个城市)的时候,跳出循环。
AC代码:
边栏推荐
- Is it still time to take the PMP Exam in September?
- 基于招聘广告的岗位人才需求分析框架构建与实证研究
- [training day3] reconstruction of roads [SPFA]
- ONNXRuntime【推理框架,用户可以非常便利的用其运行一个onnx模型】
- NFT 的 10 种实际用途
- West test Shenzhen Stock Exchange listing: annual revenue of 240million, fund-raising of 900million, market value of 4.7 billion
- 10 practical uses of NFT
- Wechat campus laundry applet graduation design finished product of applet completion work (8) graduation design thesis template
- [training day3] delete [simulation]
- new的多种使用方法
猜你喜欢

灵活易用所见即所得的可视化报表

递归方法实现最大公约数

Recursive method to realize the greatest common divisor

13、用户web层服务(一)

记账软件如何查看收入支出

知识关联视角下金融证券知识图谱构建与相关股票发现

Shell编程规范与变量

In the "meta cosmic space", utonmos will open the digital world of the combination of virtual and real

Cognition -- classic of the road to success of hardware engineers

NoSQL -- three theoretical cornerstones of NoSQL -- cap -- Base -- final consistency
随机推荐
Brief tutorial for soft exam system architecture designer | system design
阿里最新股权曝光:软银持股23.9% 蔡崇信持股1.4%
基于C语言实现线性表的建立、插入、删除、查找等基本操作
[luogu_p4820] [national training team] stack [mathematics] [physics] [harmonic progression]
[luogu_p4556] [Vani has an appointment] tail in rainy days / [template] segment tree merging
关于max做动画的一些关键信息(shift+v)
认知篇----硬件工程师的成才之路之经典
Zhishang technology IPO meeting: annual revenue of 600million, book value of accounts receivable of 270Million
Wechat campus laundry applet graduation design finished product (5) assignment
YOLOX改进之一:添加CBAM、SE、ECA注意力机制
Weice biological IPO meeting: annual revenue of 1.26 billion Ruihong investment and Yaohe medicine are shareholders
CARLA 笔记(04)— Client 和 World (创建 Client、连接 World 、批处理对象、设置 Weather、设置 Lights、World snapshots)
Cognition -- classic of the road to success of hardware engineers
Sword finger offer II 041. Average value of sliding window
Motion attitude control system of DOF pan tilt based on stm32
What open source projects of go language are worth learning
[training day4] card game [greed]
Various ways to use new
13. User web layer services (I)
Experience sharing of system architecture designers preparing for the exam: a tough battle for nearly three months