题目链接:https://www.tyvj.cn/Problem_Show.aspx?id=1023
1 #include <cstdio> 2 #include <algorithm> 3 #include <cstdlib> 4 using namespace std; 5 int a[2002],f[2002][502]; 6 int main(void) 7 { 8 //freopen("in1.txt","r",stdin); 9 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]; 10 for(int i=1;i<=n;++i) 11 for(int j=0;j<=m;++j) { 12 if(!j) for(int k=1;k<=i;++k) 13 f[i][0]=max(max(f[i-1][0],f[i-k][k]),f[i][0]); 14 else f[i][j]=f[i-1][j-1]+a[i]; 15 //printf("%d ",f[i][j]); 16 } 17 printf("\n%d\n",f[n][0]); 18 return 0; 19 }
=_=