C. George and Job
题意:在序列
中选出
个不相交大小为
的区间,使其区间和最大。
题解:
表示在前
个数里选
个区间的最大区间和。则有
代码
#include<bits/stdc++.h>
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
typedef long long LL;
using namespace std;
const int N = 5024;
int a[N];
LL sum[N], dp[N][N];
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.in","r",stdin);
#endif
ios::sync_with_stdio(false); cin.tie(0);
int n,m,k;
cin >> n >> m >> k;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
}
for(int i = 1; i <= k; ++i) {
for(int j = m; j <= n; ++j)
dp[i][j] = max(dp[i - 1][j - m] + sum[j] - sum[j - m], dp[i][j - 1]);
}
cout << dp[k][n] << endl;
return 0;
}