tyvj1023 - 奶牛的锻炼 ——DP
July 8, 2013
tyvj
DP
题目链接:https://www.tyvj.cn/Problem_Show.aspx?id=1023
#include <cstdio>
#include <algorithm>
#include <cstdlib>
using namespace std;
int a[2002],f[2002][502];
int main(void)
{
//freopen("in1.txt","r",stdin);
int n, m; scanf("%d%d",&n,&m); for(int i=1;i<=n;scanf("%d",a+i++)); f[0][0]=0,f[1][1]=a[1];
for(int i=1;i<=n;++i)
for(int j=0;j<=m;++j) {
if(!j) for(int k=1;k<=i;++k)
f[i][0]=max(max(f[i-1][0],f[i-k][k]),f[i][0]);
else f[i][j]=f[i-1][j-1]+a[i];
//printf("%d ",f[i][j]);
}
printf("\n%d\n",f[n][0]);
return 0;
}
=_=