题目:蓝桥云课-青蛙吃虫
解题代码:
#include <iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=106;
int f[N][N];
int a[N];
int t,l,r,k,n;
int main()
{
cin>>t;
while(t--){
scanf("%d%d%d%d",&n,&l,&r,&k);
memset(f,-0x3f,sizeof f);
f[0][0]=0;
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=n;i++){
for(int j=1;j<=k;j++){
for(int k=l;k<=r;k++){
if(i-k>=0){
f[i][j]=max(f[i][j],f[i-k][j-1]+a[i]);
}else{
break;
}
}
}
}
int ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=k;j++){
ans=max(ans,f[i][j]);
//cout<<f[i][j]<<" ";
}
//cout<<endl;
}
printf("%d\n",ans);
}
return 0;
}