求助60pts
查看原帖
求助60pts
667558
_Kamisato_Ayaka_楼主2022/7/2 09:18
#include<bits/stdc++.h>
using namespace std;
const int N = 10000+20;
int n,m;
int d[N],f[N][510];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>d[i];
	for(int i=0;i<n;i++){
		for(int j=0;j<=m;j++){
			f[i+1][j+1]=max(f[i+1][j+1],f[i][j]+d[i]);
			if(!j)
				f[i+1][j]=max(f[i+1][j],f[i][j]);
			else if(i+j<=n)
				f[i+j][0]=max(f[i+j][0],f[i][j]);
		}
	}
	cout<<f[n][0];
	return 0;
}
2022/7/2 09:18
加载中...