# 【BZOJ1613】[Usaco2007 Jan]Running 贝茜的晨练计划

## 样例输入 SampleInput

8 1
1
8
2
7
3
6
4
5
## 样例输出 SampleOutput 21

BZOJ 1613

Tyvj 1023

## 代码 Code

``````#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int d[10001];
int f[10001][501];
int i,j,t,n,m,l,r,k,z,y,x;
int main()
{
scanf("%d%d",&n,&m);
for (i=1;i<=n;i++) scanf("%d",&d[i]);
for (i=1;i<=n;i++)
{
f[i][0]=f[i-1][0];
for (t=1;t<=i;t++) if (t>m) break;
else
{
f[i][0]=max(f[i][0],f[i-t][t]);
}
for (j=1;j<=m;j++) f[i][j]=f[i-1][j-1]+d[i];
}
printf("%d\n",f[n][0]);
return 0;
}``````
``````program nndl1023;
var d:array[1.. 10000]of longint;
f:array[0.. 10000,0.. 500]of longint;
i,j,t,n,m,l,r,z,y,x:longint;
function max(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end;
begin
readln(n,m);
for i:=1 to n do readln(d[i]);
for i:=1 to n do
begin
f[i,0]:=f[i-1,0];
for t:=1 to i do if t>m then break else
begin
f[i,0]:=max(f[i,0],f[i-t,t]);
end;
for j:=1 to m do f[i,j]:=f[i-1,j-1]+d[i];
end;
writeln(f[n,0]);
end.``````