当前位置:网站首页>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代码:
边栏推荐
- 【图论】负环
- 基于预训练模型的多标签专利分类研究
- Weice biological IPO meeting: annual revenue of 1.26 billion Ruihong investment and Yaohe medicine are shareholders
- [training day4] card game [greed]
- GoPro access - control and preview GoPro according to GoPro official document /demo
- 13、用户web层服务(一)
- Redis implements the browsing history module
- 小程序毕设作品之微信校园洗衣小程序毕业设计成品(2)小程序功能
- 现在还来得及参加9月份的PMP考试吗?
- this指向问题,闭包以及递归
猜你喜欢
![[training day3] reconstruction of roads [SPFA]](/img/eb/4729954bf5c6c0dc85daed9ca127f7.png)
[training day3] reconstruction of roads [SPFA]

微策生物IPO过会:年营收12.6亿 睿泓投资与耀合医药是股东

Accuracy improvement method: efficient visual transformer framework of adaptive tokens (open source)

13、用户web层服务(一)

基于招聘广告的岗位人才需求分析框架构建与实证研究

Lighting 5g in the lighthouse factory, Ningde era is the first to explore the way made in China

Motion attitude control system of DOF pan tilt based on stm32

Keras deep learning practice - recommend system data coding

西测测试深交所上市:年营收2.4亿募资9亿 市值47亿

小程序毕设作品之微信校园洗衣小程序毕业设计成品(1)开发概要
随机推荐
NoSQL -- three theoretical cornerstones of NoSQL -- cap -- Base -- final consistency
Design of LR1 compiler based on C language
West test Shenzhen Stock Exchange listing: annual revenue of 240million, fund-raising of 900million, market value of 4.7 billion
[internship experience] add your own implementation method to the date tool class
Gains and losses of desensitization project
在灯塔工厂点亮5G,宁德时代抢先探路中国智造
VSCode -- 创建模板文件
[training day4] sequence transformation [thinking]
西测测试深交所上市:年营收2.4亿募资9亿 市值47亿
不需要标注数据的语义分割!ETH&鲁汶大学提出MaskDistill,用Transformer来进行无监督语义分割,SOTA!...
redis集群搭建-使用docker快速搭建一个测试redis集群
[x for x in list_a if not np.isnan(x)]和[x if not np.isnan(x) else None for x in list_a]的区别
Interview secrets are widely distributed, and the exclusive secrets of editing, testing and learning are leaked?!
A Keypoint-based Global Association Network for Lane Detection
13、用户web层服务(一)
[training day3] section [greed] [two points]
What open source projects of go language are worth learning
【2022-07-25】
Interview eight part essay · TCP protocol
Wechat campus laundry applet graduation design finished product (4) opening report