zoukankan      html  css  js  c++  java
  • bzoj 1613: [Usaco2007 Jan]Running贝茜的晨练计划 -- dp

    1613: [Usaco2007 Jan]Running贝茜的晨练计划

    Time Limit: 5 Sec  Memory Limit: 64 MB

    Description

    奶牛们打算通过锻炼来培养自己的运动细胞,作为其中的一员,贝茜选择的运动方式是每天进行N(1 <= N <= 10,000)分钟的晨跑。在每分钟的开始,贝茜会选择下一分钟是用来跑步还是休息。 贝茜的体力限制了她跑步的距离。更具体地,如果贝茜选择在第i分钟内跑步,她可以在这一分钟内跑D_i(1 <= D_i <= 1,000)米,并且她的疲劳度会增加 1。不过,无论何时贝茜的疲劳度都不能超过M(1 <= M <= 500)。如果贝茜选择休息,那么她的疲劳度就会每分钟减少1,但她必须休息到疲劳度恢复到0为止。在疲劳度为0时休息的话,疲劳度不会再变动。晨跑开始时,贝茜的疲劳度为0。 还有,在N分钟的锻炼结束时,贝茜的疲劳度也必须恢复到0,否则她将没有足够的精力来对付这一整天中剩下的事情。 请你计算一下,贝茜最多能跑多少米。

    Input

    * 第1行: 2个用空格隔开的整数:N 和 M

    * 第2..N+1行: 第i+1为1个整数:D_i

    Output

    * 第1行: 输出1个整数,表示在满足所有限制条件的情况下,贝茜能跑的最大 距离

    Sample Input

    5 2
    5
    3
    4
    2
    10


    Sample Output

    9

    输出说明:

    贝茜在第1分钟内选择跑步(跑了5米),在第2分钟内休息,在第3分钟内跑
    步(跑了4米),剩余的时间都用来休息。因为在晨跑结束时贝茜的疲劳度必须
    为0,所以她不能在第5分钟内选择跑步。

    HINT

    #include<map>
    #include<cmath>
    #include<queue>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    #define ll long long
    #define N 10010
    inline int rd()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    int f[N][520],d[N],n,m; 
    int main()
    {
        n=rd();m=rd();
        for(int i=1;i<=n;i++) d[i]=rd();
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                f[i][j]=f[i-1][j-1]+d[i];
                if(i+j<=n) f[i+j][0]=max(f[i+j][0],f[i][j]); 
            }
            f[i][0]=max(f[i-1][0],f[i][0]);
        }
        printf("%d
    ",f[n][0]);
        return 0;
    }

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    Neko's loop HDU-6444(网络赛1007)
    Parameters
    SETLOCAL
    RD / RMDIR Command
    devenv 命令用法
    Cannot determine the location of the VS Common Tools folder.
    'DEVENV' is not recognized as an internal or external command,
    How to change Visual Studio default environment setting
    error signing assembly unknown error
    What is the Xcopy Command?:
  • 原文地址:https://www.cnblogs.com/lkhll/p/6779986.html
Copyright © 2011-2022 走看看