描述

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

分析:
有三种跨栏方式,要求最短时间得完成所有跨栏(动态规划)。
反思:
查了半天DP循环发现没问题,发现是初始化写错了。
代码:

#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
int main()
{int T,T1[200],T2[200],T3[200],F1[200],F2[200];int dp[200][200];cin>>T;while(T--){int mini=INF;int n,m;memset(dp,INF,sizeof(dp));//cout<<dp[0][0];cin>>n>>m;for (int i=1;i<=n;i++)cin>>T1[i]>>T2[i]>>T3[i]>>F1[i]>>F2[i];for (int i=0;i<=m;i++){dp[0][i]=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]+T2[i]);//case 1if (j-F1[i]>=0)dp[i][j-F1[i]]=min(dp[i][j-F1[i]],dp[i-1][j]+T1[i]);//case 2if (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]);}//case 3}}/*for (int i=1;i<=n;i++){for (int j=1;j<=m;j++)cout<<dp[n][i]<<' ';cout<<endl;}*/for (int i=0;i<=m;i++){mini=min(mini,dp[n][i]);}cout<<mini<<endl;}return 0;
}

【DP】Hurdles of 110m相关推荐

  1. 【DP】【期望】$P1850$换教室

    [DP][期望]\(P1850\)换教室 链接 题目描述 有 \(2n\) 节课程安排在$ n$ 个时间段上.在第 \(i\)(\(1 \leq i \leq n\))个时间段上,两节内容相同的课程同 ...

  2. Bailian2760 数字三角形【DP】

    2760:数字三角形 描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (图1) 图1给出了一个数字三角形.从三角形的顶部到底部有很多条不同的路径.对于每条路径,把路径上面的数加起来可 ...

  3. NUC1131 Triangle【DP】

    Triangle 时间限制: 1000ms 内存限制: 65536KB 通过次数: 1总提交次数: 1 问题描述 图1表示一个数字三角形. 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 ...

  4. LeetCode:完全平方数【279】【DP】

    LeetCode:完全平方数[279][DP] 题目描述 给定正整数 n,找到若干个完全平方数(比如 1, 4, 9, 16, ...)使得它们的和等于 n.你需要让组成和的完全平方数的个数最少. 示 ...

  5. 【DP】序列 题解

    [DP]序列 题解 序列 题目 一个长度为kkk的整数序列bbb 1,bbb 2,-,bkbkbk(1≤bbb 1≤bbb 2≤-≤bkbkbk≤NNN)称为"好序列"当且仅当后一 ...

  6. poj 2411 Mondriaan#39;s Dream 【dp】

    题目:poj 2411 Mondriaan's Dream 题意:给出一个n*m的矩阵,让你用1*2的矩阵铺满,然后问你最多由多少种不同的方案. 分析:这是一个比較经典的题目.网上各种牛B写法一大堆. ...

  7. BestCoder冠军赛 - 1005 Game 【DP】

    [题意] 给出一个set,set中有几个数. 现在给出n个人,环成一圈搞约瑟夫... 开始时从第1号报数,每次从set中随机选出一个数s,等报数到s后,报s的人出圈,其他人继续报数. 最后只剩1人时, ...

  8. 【9.22校内测试】【可持久化并查集(主席树实现)】【DP】【点双联通分量/割点】...

    1 build 1.1 Description 从前有一个王国,里面有n 座城市,一开始两两不连通.现在国王将进行m 次命令,命令可 能有两种,一种是在u 和v 之间修建道路,另一种是询问在第u 次命 ...

  9. zzuliOJ 1894: 985的方格难题 【dp】

    1894: 985的方格难题 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 369  Solved: 75 Description 985走入了一个n ...

最新文章

  1. 让你的javascript函数拥有记忆功能,降低全局变量的使用
  2. 超越GhostNet!吊打MobileNetV3!MicroNet通过极低FLOPs实现图像识别(文末获取论文)
  3. Knockoutjs 实践入门 (2) 绑定事件
  4. C++学习笔记:(五)继承 多态
  5. vmware centos7 扩展容量
  6. pandas取某一索引的数据
  7. android震动服务能设置时长么,Android实现手机振动设置的方法
  8. JavaScript重难点解析1(数据类型——var、let、const区别,类型补充,“===”、“typeof”、“instanceof”区别,Symbol数据类型)
  9. 零元学Expression Design 4 - Chapter 5 教你如何用自制笔刷在5分钟内做出设计感效果...
  10. python基础知识-python基础知识,python必背内容,一、python的基
  11. 智慧解析第19集:老子开导你
  12. 敏捷与CMMI的同与不同
  13. 周鸿祎麻辣点评中国互联网公司
  14. 计算机知识演讲稿,乔布斯的演讲稿 我们的IT梦想
  15. 【云驻共创】华为云助力加速构建企业数据资产和数据治理生产线
  16. python 抓包秒杀_Python 爬虫,推荐一款简单的抓包工具(续)
  17. 康乐不风流之爱解题的pde灌水王张祖锦
  18. C语言基础知识点(领卓教育)
  19. C语言中void cpy,关于C/C++ void指针,使用void指针拷贝int 数组
  20. SAP 数据字典常用数据类型

热门文章

  1. 华为手机哪一款手机是鸿蒙系统_华为首款鸿蒙系统手机是哪一款
  2. 高德地图位置之间的平滑移动
  3. 联想一键恢复自己装(4.6)
  4. 为什么打印还要另存为_为什么打印机要打印Word文档的时候要出现另存为? 爱普生的...
  5. Windows Touch 触摸板编程
  6. linux系统导入导出mysql数据库数据
  7. linux dns配置全过程,在Linux系统下配置DNS的全过程!
  8. Vue Router 跳转拦截
  9. turtle八角图绘制
  10. 2020年有寓意的领证日期_2020年下半年领证寓意好日子,下半年适合领证的时间