显示代码纯文本
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=10000+10;
int N,M;
int f[maxn][510],A[maxn];
int main()
{
freopen("cowrun.in","r",stdin);
freopen("cowrun.out","w",stdout);
scanf("%d%d",&N,&M);
for(int i=1;i<=N;i++)scanf("%d",&A[i]);
for(int i=1;i<=N;i++)
{
f[i][0]=f[i-1][0];
for(int j=1;j<=M;j++)
{
if(i-j>=0)f[i][0]=max(f[i][0],f[i-j][j]);
f[i][j]=max(f[i][j],f[i-1][j-1]+A[i]);
}
}
printf("%d",f[N][0]);
fclose(stdin);
fclose(stdout);
return 0;
}