首页 > 代码库 > BZOJ 1613 贝茜的晨练计划

BZOJ 1613 贝茜的晨练计划

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;}

 

BZOJ 1613 贝茜的晨练计划