博客
关于我
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_real_connect 参数注意
查看>>
mysql_secure_installation初始化数据库报Access denied
查看>>
MySQL_西安11月销售昨日未上架的产品_20161212
查看>>
Mysql——深入浅出InnoDB底层原理
查看>>
MySQL“被动”性能优化汇总
查看>>
MySQL、HBase 和 Elasticsearch:特点与区别详解
查看>>
MySQL、Redis高频面试题汇总
查看>>
MYSQL、SQL Server、Oracle数据库排序空值null问题及其解决办法
查看>>
mysql一个字段为空时使用另一个字段排序
查看>>
MySQL一个表A中多个字段关联了表B的ID,如何关联查询?
查看>>
MYSQL一直显示正在启动
查看>>
MySQL一站到底!华为首发MySQL进阶宝典,基础+优化+源码+架构+实战五飞
查看>>
MySQL万字总结!超详细!
查看>>
Mysql下载以及安装(新手入门,超详细)
查看>>
MySQL不会性能调优?看看这份清华架构师编写的MySQL性能优化手册吧
查看>>
MySQL不同字符集及排序规则详解:业务场景下的最佳选
查看>>
Mysql不同官方版本对比
查看>>
MySQL与Informix数据库中的同义表创建:深入解析与比较
查看>>
mysql与mem_细说 MySQL 之 MEM_ROOT
查看>>
MySQL与Oracle的数据迁移注意事项,另附转换工具链接
查看>>