博客
关于我
ZOJ2972 Hurdles of 110m(DP)
阅读量:391 次
发布时间:2019-03-05

本文共 1633 字,大约阅读时间需要 5 分钟。

在这里插入图片描述
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.

#include
using namespace std;typedef long long ll;const int maxn=2e3+1;const int inf=0x3f3f3f3f;int dp[maxn][maxn],t1[maxn],t2[maxn],t3[maxn],f1[maxn],f2[maxn];int main(){ int T,n,m; scanf("%d",&T); while(T--) { 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]); int ans=0x3f3f3f3f; memset(dp,0x3f3f3f3f,sizeof(dp)); 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) { if(j-f1[i]>=0) dp[i][j-f1[i]]=min(dp[i][j-f1[i]],dp[i-1][j]+t1[i]);//快速模式 dp[i][j]=min(dp[i][j],dp[i-1][j]+t2[i]); //正常模式 dp[i][min(j+f2[i],m)]=min(dp[i][min(j+f2[i],m)],dp[i-1][j]+t3[i]);//慢速模式 } } for(int i=0;i<=m;++i) ans=min(ans,dp[n][i]); printf("%d\n",ans); } }

转载地址:http://hhewz.baihongyu.com/

你可能感兴趣的文章
MySQL - 解读MySQL事务与锁机制
查看>>
MTTR、MTBF、MTTF的大白话理解
查看>>
mt_rand
查看>>
mysql /*! 50100 ... */ 条件编译
查看>>
mudbox卸载/完美解决安装失败/如何彻底卸载清除干净mudbox各种残留注册表和文件的方法...
查看>>
mysql 1264_关于mysql 出现 1264 Out of range value for column 错误的解决办法
查看>>
mysql 1593_Linux高可用(HA)之MySQL主从复制中出现1593错误码的低级错误
查看>>
mysql 5.6 修改端口_mysql5.6.24怎么修改端口号
查看>>
MySQL 8.0 恢复孤立文件每表ibd文件
查看>>
MySQL 8.0开始Group by不再排序
查看>>
mysql ansi nulls_SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON 什么意思
查看>>
multi swiper bug solution
查看>>
MySQL Binlog 日志监听与 Spring 集成实战
查看>>
MySQL binlog三种模式
查看>>
multi-angle cosine and sines
查看>>
Mysql Can't connect to MySQL server
查看>>
mysql case when 乱码_Mysql CASE WHEN 用法
查看>>
Multicast1
查看>>
MySQL Cluster 7.0.36 发布
查看>>
Multimodal Unsupervised Image-to-Image Translation多通道无监督图像翻译
查看>>