题干:

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*/

【ZOJ - 2972】Hurdles of 110m (dp)相关推荐

  1. 【POJ 1187】 陨石的秘密(dp)

    题目 Description 公元11380年,一颗巨大的陨石坠落在南极.于是,灾难降临了,地球上出现了一系列反常的现象.当人们焦急万分的时候,一支中国科学家组成的南极考察队赶到了出事地点.经过一番侦 ...

  2. 【ZOJ - 4019】Schrödinger's Knapsack (dp,背包,贪心,组内贪心组间dp)

    题干: 有两种物品,k分别为k1,k2,有大小各不一的这两种物品若干,放入容量为c的背包中,能获得求最大的值.放的顺序会影响结果.每次放入一物品,其获得的值都可以用v=kr计算,r表示放入后背包剩下的 ...

  3. 【POJ - 1050】To the Max (dp)

    题干: Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguo ...

  4. 【 HDU - 5459】Jesus Is Here(dp)

    题干: I've sent Fang Fang around 201314 text messages in almost 5 years. Why can't she make sense of w ...

  5. 【AI实战】快速掌握TensorFlow(二):计算图、会话

    2019独角兽企业重金招聘Python工程师标准>>> 在前面的文章中,我们已经完成了AI基础环境的搭建(见文章:Ubuntu + Anaconda + TensorFlow + G ...

  6. 【面试系列】6种单例模式(Singleton)实现方法比较

    转载文章,文章经 LiteCodes 授权,转载至本博客. 原文地址:[面试系列]6种单例模式(Singleton)实现方法比较 下述代码均省略了 Singleton 类的业务代码段,仅表现作为单例所 ...

  7. 【深度学习】神经网络结构搜索(NAS)与多模态

    [深度学习]神经网络结构搜索(NAS)与多模态 文章目录1 概述 2 经典的NAS方法2.1 搜索空间2.2 搜索策略2.3 性能评估 3 多模态 4 多模态表示学习 Multimodal Repre ...

  8. Python之路【第二篇】:Python基础(一)

    Python之路[第二篇]:Python基础(一) 入门知识拾遗 一.作用域 对于变量的作用域,执行声明并在内存中存在,该变量就可以在下面的代码中使用. 1 2 3 if 1==1:     name ...

  9. 【常用技巧】标准模板库(STL)

    [常用技巧]标准模板库(STL) 在前几个章节中我们已经使用了诸如队列.堆.堆栈.vector 等标准模板库中的模板,切身感受到了它给我们带来的极大便利.在本节中,我们还要介绍两种标准模板--stri ...

最新文章

  1. 设计模式:简单工厂、工厂方法、抽象工厂之小结与区别
  2. CSS 背景(background)(背景颜色color、背景图片image、背景平铺repeat、背景位置position、背景附着、背景简写、背景透明、链接导航栏综合案例)
  3. iis7 php安装教程,iis7 php安装方法详解
  4. mysql锁等待问题
  5. 修手机时创意被剽窃,男子向苹果索赔7万亿!是认真的吗?
  6. linux tr 命令_在Linux中使用tr命令玩角色
  7. jetty java 实例_java 在Jetty9中使用HttpSessionListener和Filter实例详解
  8. android 半透明背景
  9. LNK2005错误的原因与解决
  10. java 邮件批量发送邮件_利用Java实现电子邮件的批量发送
  11. 欧洲人“家里蹲”,差点把美国互联网搞“瘫痪”
  12. iOS 14.5正式版如约而至 支持通过Apple Watch解锁iPhone
  13. 为什么黑客几乎不用鼠标?
  14. Linux下SD卡开发笔记(一)-SD 相关基础概念
  15. 服务器内存不足导致程序(tomcat)崩溃
  16. Hive 窗口函数(开窗函数) over
  17. 盛世乐居任命首席执行官及首席财务官
  18. 广东公立二本计算机专业比较好,广东2a大学计算机专业比较好排名
  19. 打灰机遇到的问题之 CCAnimation::addSpriteFrameWithFileName()
  20. 在Cygwin下的幸福生活

热门文章

  1. code1928: 日期差值 技巧模拟
  2. 定时器取数据时实时进来的数据_Redis-数据淘汰策略amp;持久化方式(RDB/AOF)amp;Redis与Memcached区别...
  3. micropython oled中文_micropython中怎么将gb2312编码的字节流变成中文
  4. 根据时间戳生成编号_分布式系统的唯一ID生成算法对比
  5. Vue框架之条件与循环的使用
  6. MFC 多文档源码分析1
  7. Java多进程测试用例_Pytest xdist/Pytest并行多进程执行测试用例,pytestxdistpytestparallel...
  8. 在mac上用文本编辑器写python_Mac系统Python解释器、PyCharm编辑器安装及使用方法详解...
  9. uniapp开发实例github_跨端开发痛点?送你一款Vue最流行的跨端框架——uni-app
  10. vue 计算属性和data_Vue:计算属性