博客
关于我
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 多个表求多个count
查看>>
mysql 多字段删除重复数据,保留最小id数据
查看>>
MySQL 多表联合查询:UNION 和 JOIN 分析
查看>>
MySQL 大数据量快速插入方法和语句优化
查看>>
mysql 如何给SQL添加索引
查看>>
mysql 字段区分大小写
查看>>
mysql 字段合并问题(group_concat)
查看>>
mysql 字段类型类型
查看>>
MySQL 字符串截取函数,字段截取,字符串截取
查看>>
MySQL 存储引擎
查看>>
mysql 存储过程 注入_mysql 视图 事务 存储过程 SQL注入
查看>>
MySQL 存储过程参数:in、out、inout
查看>>
mysql 存储过程每隔一段时间执行一次
查看>>
mysql 存在update不存在insert
查看>>
Mysql 学习总结(86)—— Mysql 的 JSON 数据类型正确使用姿势
查看>>
Mysql 学习总结(87)—— Mysql 执行计划(Explain)再总结
查看>>
Mysql 学习总结(88)—— Mysql 官方为什么不推荐用雪花 id 和 uuid 做 MySQL 主键
查看>>
Mysql 学习总结(89)—— Mysql 库表容量统计
查看>>
mysql 实现主从复制/主从同步
查看>>