zoukankan      html  css  js  c++  java
  • Hurdles of 110m ZOJ

     Hurdles of 110m

     ZOJ - 2972 

    In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperity of China and Beijing Olympics is to be a festival for people all over the world as well.

    Liu Xiang is one of the famous Olympic athletes in China. In 2002 Liu broke Renaldo Nehemiah's 24-year-old world junior record for the 110m hurdles. At the 2004 Athens Olympics Games, he won the gold medal in the end. Although he was not considered as a favorite for the gold, in the final, Liu's technique was nearly perfect as he barely touched the sixth hurdle and cleared all of the others cleanly. He powered to a victory of almost three meters. In doing so, he tied the 11-year-old world record of 12.91 seconds. Liu was the first Chinese man to win an Olympic gold medal in track and field. Only 21 years old at the time of his victory, Liu vowed to defend his title when the Olympics come to Beijing in 2008.

    In the 110m hurdle competition, the track was divided into N parts by the hurdle. In each part, the player has to run in the same speed; otherwise he may hit the hurdle. In fact, there are 3 modes to choose in each part for an athlete -- Fast Mode, Normal Mode and Slow Mode. Fast Mode costs the player T1 time to pass the part. However, he cannot always use this mode in all parts, because he needs to consume F1force at the same time. If he doesn't have enough force, he cannot run in the part at the Fast Mode. Normal Mode costs the player T2 time for the part. And at this mode, the player's force will remain unchanged. Slow Mode costs the player T3 time to pass the part. Meanwhile, the player will earn F2 force as compensation. The maximal force of a player is M. If he already has M force, he cannot earn any more force. At the beginning of the competition, the player has the maximal force.

    The input of this problem is detail data for Liu Xiang. Your task is to help him to choose proper mode in each part to finish the competition in the shortest time.

    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.

    题意:

    110米栏,运动员能够用三种状态跑,1状态耗体力f1且跑得快,2状态不消耗体力,3状态恢复体力f3且跑得慢。体力上限是M,且初始满体力,如今想知到最小的时间跑全然程。

    思路:

    dp[i][j]表示的是当前为第i阶段且体力剩余值为j时所用时间的最小值。i只和i-1有关,能量从0~m,我们把每一阶段的能量从0~m中能达到的遍历一遍,看看最后一个阶段中能量0~m中最大值为多少即可。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #define inf 0x3f3f3f3f
     6 using namespace std;
     7 int casen;
     8 int n,m;
     9 int dp[120][120];
    10 struct node{
    11     int t1;
    12     int t2;
    13     int t3;
    14     int f1;
    15     int f2;
    16 }e[120];
    17 int main()
    18 {
    19     cin>>casen;
    20     while(casen--)
    21     {
    22         scanf("%d%d",&n,&m);
    23         memset(dp,inf,sizeof(dp));
    24         for(int i=1;i<=n;i++)
    25         {
    26             scanf("%d%d%d%d%d",&e[i].t1,&e[i].t2,&e[i].t3,&e[i].f1,&e[i].f2);
    27         }
    28         dp[0][m]=0;
    29         for(int i=1;i<=n;i++)
    30         {
    31             for(int j=0;j<=m;j++)
    32             {
    33                 if(e[i].f1<=j)
    34                 {
    35                     int k=j-e[i].f1;
    36                     dp[i][k]=min(dp[i][k],dp[i-1][j]+e[i].t1);
    37                 }
    38                 dp[i][j]=min(dp[i][j],dp[i-1][j]+e[i].t2);
    39                 int k2=min(m,j+e[i].f2);
    40                 dp[i][k2]=min(dp[i][k2],dp[i-1][j]+e[i].t3);
    41             }
    42         }
    43         int minn=inf;
    44         for(int i=0;i<=m;i++)
    45         {
    46             minn=min(minn,dp[n][i]);
    47         }
    48         printf("%d
    ",minn);
    49     }
    50     return 0;
    51 }
  • 相关阅读:
    第一次做Java程序注意事项
    数制学习笔记
    1228作业
    1226作业(转为十进制)
    [SDOI2010] 古代猪文 (快速幂+中国剩余定理+欧拉定理+卢卡斯定理) 解题报告
    Miller-Rabin
    STL整理之set
    [HNOI2008] GT考试(DP+矩阵快速幂+KMP)
    [JZOJ4024] [佛山市选2015] 石子游戏 解题报告
    [JZOJ3383] [NOIP2013模拟] 太鼓达人 解题报告(数位欧拉)
  • 原文地址:https://www.cnblogs.com/1013star/p/10473433.html
Copyright © 2011-2022 走看看