描述

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种方式:

(1) 快跑T1秒,消耗F1能量;

(2) 正常跑T2秒,不消耗能量;

(3) 慢跑T3秒,获得F2能量;

思路:

在dp[i][j]数组中,i为第i个障碍,j为目前所拥有的能量,求第一个求跨过N个障碍所需要的最短时间。

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
int main()
{
int t,n,m,i,j,dp[][];
int t1[],t2[],t3[],f1[],f2[];
cin>>t;
while(t--)
{
int minn=INF;
memset(dp,INF,sizeof(dp));//把数组中每个元素设置为无穷大
cin>>n>>m;
for(i=;i<=n;i++)
scanf("%d%d%d%d%d",&t1[i],&t2[i],&t3[i],&f1[i],&f2[i]);
for(j=;j<=m;j++)
dp[][j]=;
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
//normal
dp[i][j]=min(dp[i][j],dp[i-][j]+t2[i]); //fast
if(j-f1[i]>=)
dp[i][j-f1[i]]=min(dp[i][j-f1[i]],dp[i-][j]+t1[i]); //slow
if(j+f2[i]<=m)//能量有余
dp[i][j+f2[i]]=min(dp[i][j+f2[i]],dp[i-][j]+t3[i]);
else//能量过剩
dp[i][m]=min(dp[i][m],dp[i-][j]+t3[i]);
}
}
for(j=;j<=m;j++)
minn=min(minn,dp[n][j]);
printf("%d\n",minn);
}
return ;
}

最新文章

  1. SQL函数汇总【精选篇】
  2. Powershell 字符串处理案例
  3. 自动生成V字型
  4. python文件操作实例
  5. Ignatius&#39;s puzzle
  6. Ubuntu上部署Ghost博客
  7. js 每秒刷新系统时间,可停止
  8. A Tour of Go If and else
  9. loadrunner11 录制脚步不成功,在录制概要出现“No Events were detected”,浮动窗口总是显示“0 Events”,解决办法
  10. [转]Xcode的重构功能
  11. FPGA中将十进制数在数码管中显示(verilog版)--二进制转换为BCD码
  12. Core Java 谈谈HashMap
  13. DataGridView操作小记(1)
  14. Flutter - BottomNavigationBar底部导航栏切换后,状态丢失
  15. angular validation 使用总结
  16. MJExtension的一些实用技巧
  17. CPU负载过高异常排查实践与总结
  18. Hibernate关系映射 一对一双向外键关联@OneToOne Annotation方式 双向关联和单向关联的区别
  19. switchsharp
  20. HDU 2298 三分

热门文章

  1. sql查询结果多对多转为一对多返回前端
  2. Vue中使用eslint
  3. ADO.NET Tips
  4. HTML 5入门知识(四)
  5. python进程与线程介绍
  6. SOL的补充
  7. koa2获取用户ip
  8. 如何用css将一个div设置为一个圆
  9. PHP腾讯与百度坐标转换
  10. DEM、DTM和DSM的区别