# zoj 2972 Hurdles of 110m(dp,背包)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2972

int dp[x][y];//跨越x个栏剩余y体力的需要的最小时间。

#include<stdio.h>//zoj 2972 dp zisu123
#include<string.h>
#include<stdlib.h>
#define INF 1<<25
typedef struct lx{
int t1,t2,t3;
int f1,f2;
}lx;
lx liu[120];
inline int min(int x,int y)
{
return x<y?x:y;
}
int main()
{
int T,N,M;
int dp[120][120];//跨越x个栏剩余y体力的需要的最小时间。
int i,j;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&N,&M);
for(i=0;i<=N;i++)
for(j=0;j<=M;j++)
dp[i][j]=INF;
dp[0][M]=0;
for(i=0;i<N;i++)
scanf("%d%d%d%d%d",&liu[i].t1,&liu[i].t2,&liu[i].t3,&liu[i].f1,&liu[i].f2);
for(i=0;i<N;i++)
for(j=0;j<=M;j++)
{
if(j>=liu[i].f1)// fastest
{
dp[i+1][j-liu[i].f1]=min(dp[i+1][j-liu[i].f1],dp[i][j]+liu[i].t1);
}
if(j+liu[i].f2>M)//slowest
{
dp[i+1][M]=min(dp[i+1][M],dp[i][j]+liu[i].t3);
}
else
{
dp[i+1][j+liu[i].f2]=min(dp[i+1][j+liu[i].f2],dp[i][j]+liu[i].t3);
}
dp[i+1][j]=min(dp[i+1][j],dp[i][j]+liu[i].t2);//normal
}
int minTime=INF;
for(i=0;i<=M;i++)
{
if(minTime>dp[N][i])
minTime=dp[N][i];
}
printf("%d\n",minTime);

}
//	system("pause");
return 0;
}

#### Hurdles of 110m ZOJ - 2972 (DP)

2018-04-18 19:23:02

#### ZOJ 2972 Hurdles of 110m（DP）

2016-02-19 17:39:12

#### ZOJ 2972 Hurdles of 110m(DP)

2014-04-06 16:46:26

#### zoj 2972 Hurdles of 110m

2015-11-11 13:48:37

#### ZOJ 2972 Hurdles of 110m

2017-04-02 10:57:29

#### ZOJ - 2972 Hurdles of 110m

2011-04-09 18:54:00

#### ZOJ - 2972 Hurdles of 110m

2015-12-03 20:24:21

#### ZOJ 2972 Hurdles of 110m

2017-02-17 21:30:07

#### zoj 2972 - Hurdles of 110m

2014-09-18 20:36:48

#### Hurdles of 110m ZOJ - 2972 (动态规划)

2018-04-19 09:07:16