描述

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种方式:快跑T1秒,消耗F1能量;普通跑T2秒,消耗0;慢跑T3秒,获得F2能量,求跨过N个障碍需要最短的时间

题解

算是一道简单的01背包问题,Dp[i][j],i为第i个障碍,j为剩余能量

  快跑:Dp[i][j-f1[i]]=min(Dp[i][j],Dp[i-1][j-f1[i]]+t1[i]);

  普通:Dp[i][j]=min(Dp[i][j],Dp[i-1][j]+t2[i]);

  慢跑:如果j+f2[i]<=m时,

      Dp[i][j+f2[i]]=min(Dp[i][j],Dp[i-1][j+f2[i]]+t3[i]);

     如果j+f2[i]>m时,这里获得能量不能超过m,多出来的能量浪费(艰难的错了WA了几次,英语渣了)

      Dp[i][m]=min(Dp[i][m],Dp[i-1][j]+t3[i]);

代码

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
int main()
{int t,n,m;scanf("%d",&t);int Dp[100][100];int t1[100],t2[100],t3[100],f1[100],f2[100];while(t--){memset(Dp,INF,sizeof(Dp));scanf("%d%d",&n,&m);for(int i=1;i<=n;i++)scanf("%d%d%d%d%d",&t1[i],&t2[i],&t3[i],&f1[i],&f2[i]);for(int j=0;j<=m;j++)Dp[0][j]=0;for(int i=1;i<=n;i++){for(int j=0;j<=m;j++){//normalDp[i][j]=min(Dp[i][j],Dp[i-1][j]+t2[i]);//fastif(j-f1[i]>=0)Dp[i][j-f1[i]]=min(Dp[i][j-f1[i]],Dp[i-1][j]+t1[i]);//slowif(j+f2[i]<=m)//不过载Dp[i][j+f2[i]]=min(Dp[i][j+f2[i]],Dp[i-1][j]+t3[i]);else//能量过载Dp[i][m]=min(Dp[i][m],Dp[i-1][j]+t3[i]);}}int minn=INF;for(int j=0;j<=m;j++)minn=min(minn,Dp[n][j]);printf("%d\n",minn);}return 0;
}

转载于:https://www.cnblogs.com/taozi1115402474/p/8447717.html

TZOJ 1545 Hurdles of 110m(01背包dp)相关推荐

  1. UVA 10163 Storage Keepers (01背包DP + 二分)

    <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...

  2. hdu 1864 最大报销额01背包dp

     最大报销额 Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Subm ...

  3. ZOJ 3703 Happy Programming Contest 0-1背包 DP

    ZOJ 3703 Happy Programming Contest 题目描述: 题目链接:ZOJ 3703 Happy Programming Contest 题目大意: 这是一道虐狗的题目.讲的是 ...

  4. ZOJ 2972 TOJ 1545 Hurdles of 110m(一般dp)

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

  5. 饭卡 01背包 DP

    电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够).所以大家 ...

  6. 51NOD 2072 装箱问题 背包问题 01 背包 DP 动态规划

    有一个箱子容量为 V(正整数,0<=V<=20000),同时有 n 个物品(0<n<=30),每个物品有一个体积(正整数). 现在在 n 个物品中,任取若干个装入箱内,使得箱子 ...

  7. POJ1015-Jury Compromise【01背包,dp】

    正题 题目链接:http://poj.org/problem?id=1015 题目大意 每个人有A值和B值,要求选M个人,使这M个人的|SumA−SumB||SumA−SumB||Sum_A-Sum_ ...

  8. 天池 在线编程 高效作业处理服务(01背包DP)

    文章目录 1. 题目 2. 解题 1. 题目 https://tianchi.aliyun.com/oj/231188302809557697/235445278655844967 Twitter正在 ...

  9. poj1015(选m个人|sumD-sumP|最小时sumD+sumP最大 输出方案 01背包dp)

    题目 傻逼.恶心.通过这个题,以后对他..恶心 题意: 在遥远的国家佛罗布尼亚,嫌犯是否有罪,须由陪审团决定.陪审团是由法官从公众中挑选的.先随机挑选n 个人作为陪审团的候选人,然后再从这n 个人中选 ...

  10. nssl1231-Gift【01背包,dp】

    正题 题目大意 n个物品,每个物品有cic_ici​元,求有多少种方案数使得无法再买另外任何的东西. 解题思路 我们发现其实对于每种方案判断只需要考虑剩下的最小的哪一个,所以我们可以将ccc从小到大排 ...

最新文章

  1. 【JavaScript总结】JavaScript语法基础:数据类型
  2. MySQL如何找到表与表之间的关系?
  3. BOOST_PREDEF_WORKAROUND宏相关的测试程序
  4. 使用git提交项目到码云
  5. python 线程锁_python多线程编程(3): 使用互斥锁同步线程
  6. 【数据结构与算法】左式堆的Java实现
  7. 爬虫—Requests高级用法
  8. 【Java】进制转换器的实现
  9. 好用的软件网址(不一定是官网,不定时更新)
  10. Word引用参考文献
  11. 粗浅的rdt协议介绍
  12. 端午节,我用Python爬取屈原的诗
  13. 成为会带团队的技术人 架构设计:治理好系统复杂度才最务实
  14. RAID 磁盘阵列与阵列卡
  15. 武汉理工大学c语言pta选择题答案,武汉理工大学c语言实验及答案.doc
  16. Java八股文--藤原豆腐店自用
  17. jquery点击图片放大效果
  18. stm32 串口下载(ISP下载)
  19. 市盈率指标详解及相关文献概述
  20. 微信小程序实现酒店入住时间区间选择日历

热门文章

  1. SQL 读取不连续的第30到40之间的数据
  2. java的main方法中的String[]args
  3. CSS 媒体类型 ,相应式布局使用
  4. Eclipse或者MyEclipse的Help菜单下找不到SoftWare Updates菜单的解决方法
  5. jar包add to build path与放入lib下
  6. Sass含中文目录编译报错
  7. SELECT 1 FROM table含义
  8. mysql交互式创建表_MySQL 必知必会 创建和操纵表
  9. 新安装的centos使用ifconfig无效或者无法使用的解决办法
  10. (day 52 - 二叉搜索树) 剑指 Offer 68 - I. 二叉搜索树的最近公共祖先