ZOJ2972 Hurdles of 110m(DP)

题目链接
在这里插入图片描述
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<bits/stdc++.h>
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); 
	} } 

发布了328 篇原创文章 · 获赞 1 · 访问量 9104

猜你喜欢

转载自blog.csdn.net/qq_42479630/article/details/105209220