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.

<b< dd="">

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.

<b< dd="">

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

<b< dd="">

Sample Output

1
6

<b< dd="">

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<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#define Inf 0x3f3f3f3f const int maxn=1e2+;
typedef long long ll;
using namespace std;
int t1[maxn],t2[maxn],t3[maxn],f1[maxn],f2[maxn];
int dp[maxn][maxn];
int n,m;
int dfs(int i,int j)
{
if(i<=)
{
return ;
}
if(dp[i][j]!=Inf)
{
return dp[i][j];
}
dp[i][j]=min(dp[i][j],dfs(i-,j)+t2[i]);
if(j>=f1[i])
{
dp[i][j]=min(dp[i][j],dfs(i-,j-f1[i])+t1[i]);
}
int temp=j+f2[i];
temp=min(temp,m);
dp[i][j]=min(dp[i][j],dfs(i-,temp)+t3[i]);
return dp[i][j]; }
int main()
{
int T;
cin>>T;
while(T--)
{
scanf("%d%d",&n,&m);
memset(dp,Inf,sizeof(dp));
dp[][m]=;
for(int t=;t<=n;t++)
{
scanf("%d%d%d%d%d",&t1[t],&t2[t],&t3[t],&f1[t],&f2[t]);
}
dfs(n,m);
printf("%d\n",dp[n][m]);
}
return ;
}

ZOJ-2972-Hurdles of 110m(记忆化搜索)的更多相关文章

  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. zoj 3644(dp + 记忆化搜索)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4834 思路:dp[i][j]表示当前节点在i,分数为j的路径条数,从 ...

  4. zoj 1107 FatMouse and Cheese(记忆化搜索)

    题目链接:点击链接 题目大意:老鼠从(0,0)出发,每次在同一个方向上最多前进k步,且每次到达的位置上的数字都要比上一个位置上的数字大,求老鼠经过的位置上的数字的和的最大值 #include<s ...

  5. zoj 3644 记忆化搜索

    题目:给出一个有向图,从1到n,每个结点有个权值,每走一步,分值为结点权值的LCM,而且每一步的LCM都要有变化,问到达N的时候分值恰好为K的路径有多少条 记忆化搜索,虽然做过很多了,但是一直比较慢, ...

  6. [ACM_动态规划] 数字三角形(数塔)_递推_记忆化搜索

    1.直接用递归函数计算状态转移方程,效率十分低下,可以考虑用递推方法,其实就是“正着推导,逆着计算” #include<iostream> #include<algorithm> ...

  7. 【BZOJ-3895】取石子 记忆化搜索 + 博弈

    3895: 取石子 Time Limit: 1 Sec  Memory Limit: 512 MBSubmit: 263  Solved: 127[Submit][Status][Discuss] D ...

  8. hdu3555 Bomb (记忆化搜索 数位DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  9. loj 1044(dp+记忆化搜索)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26764 思路:dp[pos]表示0-pos这段字符串最少分割的回文 ...

  10. DP(记忆化搜索) + AC自动机 LA 4126 Password Suspects

    题目传送门 题意:训练指南P250 分析:DFS记忆化搜索,范围或者说是图是已知的字串构成的自动机图,那么用 | (1 << i)表示包含第i个字串,如果长度为len,且st == (1 ...

随机推荐

  1. Linux本地套接字(Unix域套接字)----SOCK_DGRAM方式

    目录 简述 创建服务端代码: 创建客户端代码 接收函数封装 发送封装 服务端测试main函数 客户端测试main函数 编译运行结果 简述 这里介绍一下Linux进程间通信的socket方式---Loc ...

  2. 使用 Python 为女神挑选口红

    口红对于女生来说永远不嫌多,而男生也搞不明白珊瑚红.番茄色.斩男色等等颜色有什么区别,不都是红色么?当送给女神的口红是她不适合的,那结果就是口红进入垃圾箱还算是轻的,重则拉黑处理.男生们也不用着急,我 ...

  3. linux常用命令(二)服务器硬件资源信息

    内存:free -m 硬盘:df -h 负载:w/top cpu个数和核数:cat /proc/cpuinfo

  4. Java—面向对象、类与对象、封装

    理解什么是面向过程.面向对象 面向过程与面向对象都是我们编程中,编写程序的一种思维方式. 面向过程的程序设计方式,是遇到一件事时,思考“我该怎么做”,然后一步步实现的过程. 面向对象的程序设计方式,是 ...

  5. externaltrafficpolicy的有关问题说明

    环境描述 生产环境通过gitlab-running实现自动化发布业务,现需要收集客户端的真实ip,需要将externaltrafficpolicy改为lacal模式(原来是cluster模式),前天开 ...

  6. 详解Java线程池的ctl(线程池控制状态)【源码分析】

    0.综述 ctl 是线程池源码中常常用到的一个变量. 它的主要作用是记录线程池的生命周期状态和当前工作的线程数. 作者通过巧妙的设计,将一个整型变量按二进制位分成两部分,分别表示两个信息. 1.声明与 ...

  7. Linux用户锁定、解锁及锁定查看

    [root@l01 ~]# passwd -S pispread pispread PS -- - (Password set, SHA512 crypt.)用户锁定 [root@l01 ~]# pa ...

  8. moonlight不显示鼠标指针

    多显示屏导致moonlight不显示鼠标指针, 使用的时候关闭其他显示屏,只使用一个显示屏,就可以正常显示了.

  9. 牛X!看完阿里P8架构师推荐的spring三剑客,成功涨薪5k

    一直以来,Spring都被Java程序员视为杀手级别的应用,是为简化Java EE应用程序的开发为目标而创建的.Spring可以做很多事情,它为企业级开发提供给了丰富的功能,但是这些功能的底层都依赖于 ...

  10. 最新通达OA-getshell 漏洞复现

    0x00 通达简介 通达OA国内常用的办公系统,使用群体,大小公司都可以,其此次安全更新修复的高危漏洞为任意用户登录漏洞.攻击者在远程且未经授权的情况下,通过利用此漏洞,可以直接以任意用户身份登录到系 ...