【ZOJ - 2972】Hurdles of 110m (dp)

题干:

In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperity of China and Beijing Olympics is to be a festival for people all over the world as well.

Liu Xiang is one of the famous Olympic athletes in China. In 2002 Liu broke Renaldo Nehemiah's 24-year-old world junior record for the 110m hurdles. At the 2004 Athens Olympics Games, he won the gold medal in the end. Although he was not considered as a favorite for the gold, in the final, Liu's technique was nearly perfect as he barely touched the sixth hurdle and cleared all of the others cleanly. He powered to a victory of almost three meters. In doing so, he tied the 11-year-old world record of 12.91 seconds. Liu was the first Chinese man to win an Olympic gold medal in track and field. Only 21 years old at the time of his victory, Liu vowed to defend his title when the Olympics come to Beijing in 2008.

In the 110m hurdle competition, the track was divided into N parts by the hurdle. In each part, the player has to run in the same speed; otherwise he may hit the hurdle. In fact, there are 3 modes to choose in each part for an athlete -- Fast Mode, Normal Mode and Slow Mode. Fast Mode costs the player T1 time to pass the part. However, he cannot always use this mode in all parts, because he needs to consume F1force at the same time. If he doesn't have enough force, he cannot run in the part at the Fast Mode. Normal Mode costs the player T2 time for the part. And at this mode, the player's force will remain unchanged. Slow Mode costs the player T3 time to pass the part. Meanwhile, the player will earn F2 force as compensation. The maximal force of a player is M. If he already has M force, he cannot earn any more force. At the beginning of the competition, the player has the maximal force.

The input of this problem is detail data for Liu Xiang. Your task is to help him to choose proper mode in each part to finish the competition in the shortest time.

Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 50) which is the number of test cases. And it will be followed by T consecutive test cases.

Each test case begins with two positive integers N and M. And following N lines denote the data for the N parts. Each line has five positive integers T1 T2 T3 F1 F2. All the integers in this problem are less than or equal to 110.

Output

Results should be directed to standard output. The output of each test case should be a single integer in one line, which is the shortest time that Liu Xiang can finish the competition.

Sample Input

2
1 10
1 2 3 10 10
4 10
1 2 3 10 10
1 10 10 10 10
1 1 2 10 10
1 10 10 10 10

Sample Output

1
6

Hint

 

For the second sample test case, Liu Xiang should run with the sequence of Normal Mode, Fast Mode, Slow Mode and Fast Mode.

题目大意:

110米栏,运动员可以用三种状态跑,1状态耗体力且跑得快,2状态不消耗体力,3状态恢复体力且跑得慢。体力上限是M,且初始满体力,现在想知到最小的时间跑完全程。

解题报告:

   多阶段决策问题,考虑dp。dp[i][j]代表前i个阶段,所剩能量为j的最短时间。

    分情况转移就好了。注意对于满状态的时候,不仅可以由“可以使得刚刚好满状态”的状态转移过来,还可以由中间这些状态转移过来。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
const int MAX = 2e5 + 5;
const int INF = 0x3f3f3f3f;
ll n,m;
struct Node {int t1,t2,t3,f1,f2;
} p[MAX];
int dp[155][155];//第i个阶段 还剩j能量 的最短时间 
int main()
{int t;cin>>t;while(t--) {cin>>n>>m;for(int i = 1; i<=n; i++) {scanf("%d%d%d%d%d",&p[i].t1,&p[i].t2,&p[i].t3,&p[i].f1,&p[i].f2);}memset(dp,INF,sizeof dp);//?????????????????????dp[0][m] = 0;for(int i = 1; i<=n; i++) {for(int j = 0; j<=m; j++) {//匀速 dp[i][j] = min(dp[i][j],dp[i-1][j] + p[i].t2);//加速 if(j+p[i].f1 <=m) dp[i][j] = min(dp[i][j],dp[i-1][j+p[i].f1] + p[i].t1);//减速if(j == m) {for(int k = max(0,j-p[i].f2); k<=m; k++) {dp[i][j] = min(dp[i][j],dp[i-1][k] + p[i].t3);}}else if(j-p[i].f2 >= 0) dp[i][j] = min(dp[i][j],dp[i-1][max(j-p[i].f2,0)] + p[i].t3);}}int ans = INF;for(int j = 0 ; j<=m; j++) ans = min(ans,dp[n][j]);printf("%d\n",ans);}return 0 ;
}
/*
1
1 4
10 5 3 10 10*/

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440656.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

格式说明_ISO11784/85 FDX-B动物芯片格式写码说明

植入式生物芯片口蹄疫、疯牛病、禽流感、非洲猪瘟的蔓延严重危及人类生命安全&#xff0c;引发了人们对动物性食品生产全过程安全追溯管理的重视。因此&#xff0c;有效地利用非接触式无线射频技术(RFID)对其进行控制成为有效的重要手段。一、国际动物识别标准介绍ISO 11784&am…

1至9填入九个方框内_防水涂料和施工堵漏的“五大技巧”和“九个细节”

防水涂料和施工堵漏的“五大技巧”和“九个细节”很多业主会在留言里问我家里水管堵了、房顶渗水怎么办&#xff0c;所以防水问题不可忽视。让您住的安心&#xff0c;您楼下的邻居也住的安心。对于防水问题&#xff0c;一定要在最初进行装修的时候就特别注意。下面这些是专业人…

限制 计算机中 某用户上网 win7,利用win7限制上网时间的方法

随着电脑的普及&#xff0c;很多家长为了让自己的孩子能有更广泛的知识&#xff0c;都给自己的孩子买了电脑&#xff0c;可现在很多孩子使用电脑却很少耗费在学习上&#xff0c;更多的时间是在娱乐&#xff0c;这样不仅影响学习而且还影响着视力&#xff0c;这样的问题相信困扰…

【ZOJ - 2976】Light Bulbs (枚举,暴力)

题干&#xff1a; Wildleopard had fallen in love with his girlfriend for 20 years. He wanted to end the long match for their love and get married this year. He bought a new house for his family and hired a company to decorate his house. Wildleopard and his…

为什么计算机编程以英语为主,为什么做编程都用英文,中文不行吗?听程序员解释完,总算明白了...

今天我们科普的话题是&#xff1a;为什么做编程都用英文&#xff0c;中文不行吗&#xff1f;听程序员解释完&#xff0c;总算明白了不知道大家最近有没有追过一部电视剧&#xff0c;它是《亲爱的热爱的》&#xff0c;由李现和杨紫主演的。主要讲述了这对情侣发生的浪漫爱情故事…

html的技术标准网站,HTML5标准最新技术预览

已经存在近十年的HTML4已经成为不断发展的Web开发领域的瓶颈&#xff1b;HTML5标准在此时显得尤为重要。每天都有新颖而创新的网站出现&#xff0c;全方位地拓展HTML的边界。Web开发者正在寻求新的技术&#xff0c;提供更强大的功能&#xff0c;那些因为脚本语言和浏览器的限制…

计算机网络技术实验,计算机网络技术实验

计算机网络技术实验 实 验 一 (2课时) 课题(项目)名称: 基本网络命令 计划学时: 2学时 实验目的 1. 了解网络命令的基本使用方法 2. 掌握常用网络命令的应用 3. 掌握网络通达性的基本测试方法 实验要求 1. 全面了解各种网络命令 2. 对常用的网络命令&#xff0c;上机测试运行 3…

html div分钟刷新一次啊代码_接口测试平台代码实现57首页重构5

本节我们接着开发首页&#xff0c;主要内容是 让左侧的请求记录和右侧的请求模块 联动起来。具体联动需求&#xff1a;右侧请求一次之后&#xff0c;左侧生成记录点击左侧记录&#xff0c;右侧则会显示这次记录的请求数据我们本节课的内容是想办法实现1-生成记录。我们知道&…

会计专业领域计算机应用系统,信息技术在会计专业领域中的应用

在当今这个信息时代,信息技术对会计专业产生了重大的变革。本文在详细分析会计信息化特征的基础上,阐述了由于信息技术应用对会计职能产生的影响,并提出了如何更好的在会计专业领域推广信息技术。信息技术在会计专业领域中的应用郑晨(福建农林大学计算机与信息学院&#xff0c;…

固定 顶部_纹络型温室大棚顶部通风样式及效率对比

纹络型温室大棚是一种使用玻璃作为覆盖材料的温室大棚&#xff0c;该种温室大棚由于抗风雪能力强&#xff0c;环境控制能力强、使用年限长&#xff0c;目前在我国的南北地区大量建造。由于该型号的玻璃温室大棚单体占地面积能够达到几十亩地&#xff0c;因此单靠墙面通风无法满…

微型计算机智能体重评测,荣耀智能体脂秤WiFi版评测:17项身体指标 比你更懂你...

原标题&#xff1a;荣耀智能体脂秤WiFi版评测&#xff1a;17项身体指标 比你更懂你[PConline 评测]俗话说冬天不减肥&#xff0c;夏天徒伤悲&#xff0c;每个人都希望拥有穿衣显瘦、脱 衣有肉的完美身材。但往往理想很丰满&#xff0c;现实很骨感&#xff0c;很多人都陷入减肥的…

人脑意识转入量子计算机,人脑产生意识:可能是因为量子纠缠

图片来源&#xff1a;quanta magazine一提到“量子意识”这个词语&#xff0c;大多数物理学家都会选择避而不谈&#xff0c;因为这个词语听起来好像有点“民科”&#xff0c;甚至让人联想宗教或者玄学。不过出人意料的是&#xff0c;量子效应可能真的在人类的认知过程中起到了一…

【ZOJ - 1163】The Staircases(dp)

题干&#xff1a; One curious child has a set of N little bricks. From these bricks he builds different staircases. Staircase consists of steps of different sizes in a strictly descending order. It is not allowed for staircase to have steps equal sizes. Ev…

的级联选择_级联接收机的计算及Y因子噪声因子测量法

对于RF系统工程师来说&#xff0c;计算噪声系数预算对预测产品性能至关重要。一、级联接收机的计算这部分讨论噪声系数的一般概念&#xff0c;以及产品定义和电路设计者如何利用噪声系数表示噪声性能要求。噪声系数也用于预测接收机系统的总体灵敏度。也介绍级联接收机的噪声系…

免费测试英语发音的软件,2020英语音标免费版

2020英语音标免费版是一款安卓手机英语音标内容学习软件&#xff0c;在这里汇集了英语音标相关内容学习&#xff0c;包含了音标、发音等内容学习&#xff0c;能够进行对比练习&#xff0c;不断对比&#xff0c;让发音更标准&#xff0c;拥有详细的发音知识可以学习&#xff0c;…

W10的服务器正在运行,win10开机提示服务器正在运行中的解决教程

今天小编给大家分享的是win10开机提示服务器正在运行中的解决教程。最近有win10的用户反映&#xff0c;在开机的时候莫名的就出现了个“服务器正在运行中”的气泡提示&#xff0c;出现此问题困扰的用户&#xff0c;请来看看下面的解决教程吧。使用win10系统过程中&#xff0c;在…

host ntrip 千寻rtk_最新测量干货:南方银河1和银河1Plus RTK设备连接千寻cors账号的设置方法...

无论刚接触网络RTK的测量员是想要进行华测RTK连接千寻cors账号的操作&#xff0c;还是中海达RTK连接千寻cors账号&#xff0c;亦或者司南RTK连接千寻cors账号的操作&#xff0c;我们在进行cors账号的连接操作之前都应该对操作的RTK设备有一个了解&#xff0c;所以今天我们在给大…

【CodeForces - 1084D】The Fair Nut and the Best Path (树形dp)

题干&#xff1a; The Fair Nut is going to travel to the Tree Country, in which there are nn cities. Most of the land of this country is covered by forest. Furthermore, the local road system forms a tree (connected graph without cycles). Nut wants to rent …

python不同曲线设置标签_【图像分类】基于Pascal VOC2012增强数据的多标签图像分类实战...

接着上一次的多标签分类综述&#xff0c;本文主要以Pascal VOC2012增强数据集进行多标签图像分类训练&#xff0c;详细介绍增强数据集制作、训练以及指标计算过程&#xff0c;并通过代码进行详细阐述&#xff0c;希望能为大家提供一定的帮助&#xff01;作者&编辑 | 郭冰洋…

表字段注释放在哪_橱柜台面6种材质优缺点大解剖,我来测评,告诉你哪一种适合你!...

很多人装修厨房&#xff0c;只知道橱柜要好用&#xff0c;厨房才好用。但在做橱柜的时候&#xff0c;除了橱柜的选择&#xff0c;很多装修新手还会遇到一些其他疑问&#xff1a;① 橱柜的台面用什么材质的比较好&#xff1f;② 台面的挡水条到底要不要做&#xff1f;③ 橱柜台面…