BZOJ 1613 贝茜的晨练计划

Posted on 2016-10-02 11:13  ziliuziliu  阅读(122)  评论(0编辑  收藏  举报

DP.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,d[10050],f[10050],dp[20050][505];
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++) scanf("%d",&d[i]);
    for (int i=1;i<=n;i++)
    {
        dp[i][1]=f[i-1]+d[i];f[i+1]=max(f[i+1],dp[i][1]);f[i+1]=max(f[i+1],f[i]);
        for (int j=2;j<=m;j++)
        {
            dp[i][j]=dp[i-1][j-1]+d[i];
            f[i+j]=max(f[i+j],dp[i][j]);    
        }        
    }    
    printf("%d\n",f[n]);
    return 0;
}