【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…

html手机网站font-size:16em,px、em、rem

px、em、rempx 是固定的长度单位em 是父元素的font-size(字体大小)的值&#xff0c;常用来设置首行缩进2em(2字符)rem 是根节点(html&#xff0c;body)的font-size(字体大小)的值&#xff0c;可以用来做移动端的自适应。为什么要适配移动端px像素(pixel)相对长度单位。相对于显…

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…

dataframe去重复 python_python – 在DataFrame中组合重复的列

如果我的数据框具有包含相同名称的列,是否有办法将具有相同名称的列与某种功能(即总和)组合在一起&#xff1f;例如&#xff1a;In [186]:df["NY-WEB01"].head()Out[186]:NY-WEB01 NY-WEB01DateTime2012-10-18 16:00:00 5.6 2.82012-10-18 17:00:00 18.6 12.02012-10…

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

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

【HRBUST - 1613】迷宫问题 (bfs)

题干&#xff1a; 小z身处在一个迷宫中&#xff0c;小z每分钟可以走到上下左右四个方向的相邻格之一。迷宫中有一些墙和障碍物。 同时迷宫中也有一些传送门&#xff0c;当小z走到任意一个传送门时&#xff0c;可以选择传送到其他任意的传送门(传送是不花费时间的)&#xff0c;…

eclipse 跑maven命令_eclipse中运行maven命令没有反应,console也不出现信息

eclipse的maven项目中&#xff0c;在run as/Debug as 执行maven命令的时候发现毫无反应&#xff0c;console也不打印信息原因是因为没有传参数&#xff0c;解决办法如下&#xff1a;1.打开eclipse的window菜单&#xff1a;Preferences -->?Java?--> Installed JREs2.选…

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

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

【Hihocoder - offer编程练习赛86 - C】跳数游戏(STLset或map预处理,dp)

题干&#xff1a; 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一个长度为N的数组A1, A2, ... AN&#xff0c;请你判断其中有几个元素Ai按如下跳跃规则能跳到最后一个元素AN。 假设你当前位于Ai&#xff0c;跳跃的规则是&#xff1a; 如果这一步是第奇…

linux+平均磁盘请求数量_Linux 查看磁盘IO并找出占用IO读写很高的进程

背景-线上告警线上一台服务器告警&#xff0c;磁盘利用率 disk.util > 90&#xff0c;并持续告警。登录该服务器后通过 iostat -x 1 10 查看了相关磁盘使用信息。相关截图如下&#xff1a;# 如果没有 iostat 命令&#xff0c;那么使用 yum install sysstat 进行安装# iostat…

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

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

【7-10 PAT】树的遍历(给定一棵二叉树的后序遍历和中序遍历,请你输出其层序遍历的序列。)

题干&#xff1a; 给定一棵二叉树的后序遍历和中序遍历&#xff0c;请你输出其层序遍历的序列。这里假设键值都是互不相等的正整数。 解题报告&#xff1a; dfs求出这棵树来&#xff0c;然后bfs求层序遍历就行了。 AC代码&#xff1a; #include<cstdio> #include<…

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

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

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

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

【ZOJ - 3703】Happy Programming Contest(带优先级的01背包,贪心背包)

题干&#xff1a; In Zhejiang University Programming Contest, a team is called "couple team" if it consists of only two students loving each other. In the contest, the team will get a lovely balloon with unique color for each problem they solved.…

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

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

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

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

【ZOJ - 3211】Dream City (01背包类问题,贪心背包)

题干&#xff1a; JAVAMAN is visiting Dream City and he sees a yard of gold coin trees. There are n trees in the yard. Lets call them tree 1, tree 2 ...and tree n. At the first day, each tree i has ai coins on it (i1, 2, 3...n). Surprisingly, each tree i c…