描述

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 F1 force 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.

输入

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.

输出

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.

样例输入

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

样例输出

1
6

提示

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

题意:

共有N个障碍需要跨越,而跨过障碍有3种方式:

(1) 快跑T1秒,消耗F1能量;

(2) 正常跑T2秒,不消耗能量;

(3) 慢跑T3秒,获得F2能量;

思路:

在dp[i][j]数组中,i为第i个障碍,j为目前所拥有的能量,求第一个求跨过N个障碍所需要的最短时间。

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
int main()
{
int t,n,m,i,j,dp[][];
int t1[],t2[],t3[],f1[],f2[];
cin>>t;
while(t--)
{
int minn=INF;
memset(dp,INF,sizeof(dp));//把数组中每个元素设置为无穷大
cin>>n>>m;
for(i=;i<=n;i++)
scanf("%d%d%d%d%d",&t1[i],&t2[i],&t3[i],&f1[i],&f2[i]);
for(j=;j<=m;j++)
dp[][j]=;
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
//normal
dp[i][j]=min(dp[i][j],dp[i-][j]+t2[i]); //fast
if(j-f1[i]>=)
dp[i][j-f1[i]]=min(dp[i][j-f1[i]],dp[i-][j]+t1[i]); //slow
if(j+f2[i]<=m)//能量有余
dp[i][j+f2[i]]=min(dp[i][j+f2[i]],dp[i-][j]+t3[i]);
else//能量过剩
dp[i][m]=min(dp[i][m],dp[i-][j]+t3[i]);
}
}
for(j=;j<=m;j++)
minn=min(minn,dp[n][j]);
printf("%d\n",minn);
}
return ;
}

【TOJ 1545】Hurdles of 110m(动态规划)的更多相关文章

  1. TZOJ 1545 Hurdles of 110m(01背包dp)

    描述 In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperit ...

  2. zju 2972 Hurdles of 110m(简单的dp)

    题目 简单的dp,但是我还是参考了网上的思路,具体我没考虑到的地方见代码 #include<stdio.h> #include<iostream> #include<st ...

  3. ZOJ 2972 Hurdles of 110m 【DP 背包】

    一共有N段过程,每段过程里可以选择 快速跑. 匀速跑 和 慢速跑 对于快速跑会消耗F1 的能量, 慢速跑会集聚F2的能量 选手一开始有M的能量,即能量上限 求通过全程的最短时间 定义DP[i][j] ...

  4. zoj 2972 - Hurdles of 110m

    题目:110米栏,运动员能够用三种状态跑,1状态耗体力且跑得快,2状态不消耗体力,3状态恢复体力且跑得慢. 体力上限是M,且初始满体力,如今想知到最小的时间跑全然程. 分析:dp,全然背包.题目是一个 ...

  5. 【TOJ 1072】编辑距离(动态规划)

    描述 假设字符串的基本操作仅为:删除一个字符.插入一个字符和将一个字符修改成另一个字符这三种操作. 我们把进行了一次上述三种操作的任意一种操作称为进行了一步字符基本操作. 下面我们定义两个字符串的编辑 ...

  6. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  7. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  8. ZOJ-2972-Hurdles of 110m(线性dp)

    Hurdles of 110m Time Limit: 2 Seconds      Memory Limit: 65536 KB In the year 2008, the 29th Olympic ...

  9. QDU_组队训练(ABEFGHKL)

    A - Accurately Say "CocaCola"! In a party held by CocaCola company, several students stand ...

随机推荐

  1. MyBatis 中 sqlmapconfig核心标签说明以及配置

    文件介绍 对于 MyBatis 最核心的全局配置文件是 sqlmapConfig.xml 文件,其中包含了数据库的连接配置信息.Mapper 映射文件的加载路径.全局参数.类型别名等. 配置项详解 标 ...

  2. final关键字介绍

    许多程序设计语言都有自己的办法告诉编译器某个数据是“常数”.常数主要应用于下述两个方面: (1) 编译期常数,它永远不会改变 (2) 在运行期初始化的一个值,我们不希望它发生变化 对于编译期的常数,编 ...

  3. 从零开始的全栈工程师——JS面向对象(复习)

    作用域 栈内存:js执行的环境堆内存:存放代码块的空间 存放方式 键值对形式存放 字符串的形式存放js在执行之前 浏览器会给他一个全局作用域叫window 每个作用域下都分为两个模块 一个是内存模块一 ...

  4. CSS中关于linebox的baseline位置移动的理解

    前言 最近看到一篇文章,弗里得木的翻译笔记,里面有个问题没有解决,就是linebox的baseline为什么会移动呢? 在讨论这个问题之前读者需要对 默认值baseline 以及 其他属性值(天镶的博 ...

  5. 提取url中参数的方法(转换成json格式)

    还是直接上代码吧. //将url中的参数获取到并抓换成json格式 function serilizeUrl(url){ var urlObject={}; //1.正则匹配是不是以?结尾 if(/\ ...

  6. boost库的配置——Linux篇

    Boost库分为两个部分来使用,一是直接使用对应的头文件,二是需要编译安装相应的库才可以使用. 下面是boost在Linux上安装和使用过程(整个boost库全部安装): (1)在www.boost. ...

  7. 用java实现一个简单的单用户登陆功能的思路

    引用 所谓“单用户单账户登录”是指:在同一系统中,一个用户名不能在两个地方同时登录. 我们参照 QQ 实现效果:当某账号在 A 处登录后,在未退出的情况下,如果再到 B 处登录,那么,系统会挤下 A ...

  8. geth访问公有链

    同步以太坊,配置rpc地址 mkdir /opt/blockchain nohup geth --syncmode "fast" --cache=1024 --maxpeers 3 ...

  9. SQL Server ->> Move characters in string N position(s) forward/backward based on ASCII table(根据ASCII表的排列顺序将字符串内的数值往前或者后移N个位)

    去年无聊的时候想到想玩一下根据ASCII表的排列顺序将字符串内的数值往前或者后移N个位,顺便看一下是T-SQL性能好还是用C#写CLR函数处理得快.结果是在50万行以下其实两者差距很小,当然这是在我的 ...

  10. win7 下vs2008试用版破解

    用过微软的开发套件Visual Studio 2008,如果用的是试用版本,超过90天,就会过期,出现下面这张图片显示的 下面介绍破解的步骤: 1.首先打开控制面板——然后找到卸载或更改程序——然后找 ...