博客
关于我
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数据库导入导出_windows系统以及linux系统下的操作---linux工作笔记042
查看>>
mysql数据库导出导入
查看>>
mysql数据库常用命令
查看>>
mysql数据库扫盲,你真的知道什么是数据库嘛
查看>>
mysql数据库批量插入数据shell脚本实现
查看>>
MySQL数据库操作
查看>>
MySQL数据库故障排错
查看>>
MySQL数据库无法远程连接的解决办法
查看>>
mysql数据库时间类型datetime、bigint、timestamp的查询效率比较
查看>>
MySQL数据库服务器端核心参数详解和推荐配置(一)
查看>>
mysql数据库死锁的产生原因及解决办法
查看>>
MySQL数据库的事务管理
查看>>
mysql数据库的备份与恢复
查看>>
Mysql数据库的条件查询语句
查看>>
MySQL数据库的高可用
查看>>
MYSQL数据库简单的状态检查(show processlist)
查看>>
MYSQL数据库简单的状态检查(show status)
查看>>
MySQL数据库系列
查看>>
MYSQL数据库自动本地/异地双备份/MYSQL增量备份
查看>>