简单dp,设计状态为前i个数取j组的最大值
#include<iostream> #include<cstring> #include<cstdio> #include<map> #include<algorithm> #define ull unsigned long long using namespace std; typedef long long ll; const int N=1e5+10; ll f[5010][5004]; ll s[N]; ll a[N]; int main(){ int i; int n,m,k; cin>>n>>m>>k; for(i=1;i<=n;i++){ scanf("%lld",&a[i]); s[i]=s[i-1]+a[i]; } int j; for(i=m;i<=n;i++){ for(j=1;j<=k;j++){ f[i][j]=max(f[i-1][j],f[i-m][j-1]+s[i]-s[i-m]); } } cout<<f[n][k]<<endl; }