Hurdles of 110m


Time Limit: 2 Seconds      Memory Limit: 65536 KB

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.

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

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int t,n,m,ans;
int t1[],t2[],t3[],f1[],f2[];
int dp[][];//dp[i][j]表示第i个障碍,还剩j的能力时最短是时间
int main()
{
while(~scanf("%d",&t))
{
for(;t>;t--)
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
scanf("%d%d%d%d%d",&t1[i],&t2[i],&t3[i],&f1[i],&f2[i]);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
dp[i][j]=;
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
{
/*
dp[i][j]=dp[i-1][j]+t2[i];
if (j+f1[i]<=m) dp[i][j]=min(dp[i][j],dp[i-1][j+f1[i]]+t1[i]);
if(j>=f2[i]) dp[i][j]=min(dp[i][j],dp[i-1][j-f2[i]]+t3[i]);
//想了半天,突然想到,这样写,让选用三方案后能量超过m的情况被忽略了。
*/
dp[i][j]=min(dp[i][j],dp[i-][j]+t2[i]);
if (j>=f1[i]) dp[i][j-f1[i]]=min(dp[i][j-f1[i]],dp[i-][j]+t1[i]);
dp[i][min(j+f2[i],m)]=min(dp[i][min(j+f2[i],m)],dp[i-][j]+t3[i]);
}
/* for(int i=1;i<=n;i++)
{
for(int j=0;j<=m;j++)
printf("%d ",dp[i][j]);
printf("\n");
}*/
ans=;
for(int i=;i<=m;i++)
ans=min(ans,dp[n][i]);
printf("%d\n",ans);
}
}
return ;
}

ZOJ-2972-Hurdles of 110m(线性dp)的更多相关文章

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

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

  2. zoj 2972 - Hurdles of 110m

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

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

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

  4. 动态规划——线性dp

    我们在解决一些线性区间上的最优化问题的时候,往往也能够利用到动态规划的思想,这种问题可以叫做线性dp.在这篇文章中,我们将讨论有关线性dp的一些问题. 在有关线性dp问题中,有着几个比较经典而基础的模 ...

  5. LightOJ1044 Palindrome Partitioning(区间DP+线性DP)

    问题问的是最少可以把一个字符串分成几段,使每段都是回文串. 一开始想直接区间DP,dp[i][j]表示子串[i,j]的答案,不过字符串长度1000,100W个状态,一个状态从多个状态转移来的,转移的时 ...

  6. Codeforces 176B (线性DP+字符串)

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=28214 题目大意:源串有如下变形:每次将串切为两半,位置颠倒形成 ...

  7. hdu1712 线性dp

    //Accepted 400 KB 109 ms //dp线性 //dp[i][j]=max(dp[i-1][k]+a[i][j-k]) //在前i门课上花j天得到的最大分数,等于max(在前i-1门 ...

  8. POJ 2479-Maximum sum(线性dp)

    Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 33918   Accepted: 10504 Des ...

  9. poj 1050 To the Max(线性dp)

    题目链接:http://poj.org/problem?id=1050 思路分析: 该题目为经典的最大子矩阵和问题,属于线性dp问题:最大子矩阵为最大连续子段和的推广情况,最大连续子段和为一维问题,而 ...

随机推荐

  1. pom.xml文件报错:web.xml is missing and <failOnMissingWebXml> is set to true

    这个错误原因是因为项目无法加载到web.xml,所以需要配置web项目的目录.具体解决,配置步骤如下: 1.右键项目属性,配置项目目录  /src/main/webapp,如果没有,新增一条 2.配置 ...

  2. RabbitMQ学习之(三)_Centos6下RabbitMQ PHP扩展的安装

    安装rabbitmq-c依赖包 yum install libtool autoconf 下载安装rabbitmq-c wget https://github.com/alanxz/rabbitmq- ...

  3. spring boot开发为什么使用jar包

    spring boot既可以打成war发布,也可以找成jar包发布. jar包:直接通过内置tomcat运行,不需要额外安装tomcat.如需修改内置tomcat的配置,只需要在spring boot ...

  4. php下获取http状态的实现代码

    在项目开发中,有时我们需要知道远程的URL地址是否能访问正常,判断其正常与否后进行下一步的操作,那么在PHP中如何获取远程HTTP的状态呢? 文件preg.php header("HTTP/ ...

  5. hello java !

    我对于计算机性编程性质的课程一直没有很好的悟性,但功夫不服有心,最近自己学习视频课程,随时关注娄老师的博客,慢慢的对于java编程有了新的认识,也用eclipse软件进行了简单java的编译. 了解的 ...

  6. 解读:CombineFileInputFormat类

    MR-Job默认的输入格式FileInputFormat为每一个小文件生成一个切片.CombineFileInputFormat通过将多个“小文件”合并为一个"切片"(在形成切片的 ...

  7. NuGet version

    https://stackoverflow.com/questions/15964935/get-nuget-exe-version-from-command-line Typing nuget he ...

  8. Axis.Labels.CustomSize

    tChart1.Axes.Bottom.Labels.CustomSize = ; //Changes spacing occupied by the axis labels between the ...

  9. bzoj1879: [Sdoi2009]Bill的挑战(codevs2308)(luoguP2167) 状压dp

    唔...懒兔子来写博客了... 点我看题 这题的话...我想了很久但是都不是可行解 刚开始想预处理任意两个串是否可以匹配然后在乱搞,后来发现完全不会写... 然后按照惯例,我会看题解认真的思考... ...

  10. jar包中使用log4j2不起作用

    某程序中有使用到log4j2,将该程序打包成jar,使用以下命令执行时,发现log4j不输出 java -cp Tool.jar com.zhen.nameOnce.Log4jTest 且报以下错误 ...