標籤:http io os ar for div sp cti on
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn‘t have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.
Given a sequence of n integers p1,?p2,?...,?pn. You are to choosek pairs of integers:
[
l
1,?r1],?[l2,?r2],?...,?[lk,?rk] (1?≤?l1?≤?r1?<?l2?≤?r2?<?...?<?lk?≤?rk?≤?n; ri?-?li?+?1?=?m),?
in such a way that the value of sum is maximal possible. Help George to cope with the task.
Input
The first line contains three integers n,m and k(1?≤?(m?×?k)?≤?n?≤?5000). The second line containsn integers p1,?p2,?...,?pn(0?≤?pi?≤?109).
Output
Print an integer in a single line — the maximum possible value of sum.
Sample test(s)Input
5 2 11 2 3 4 5
Output
9
Input
7 1 32 10 7 18 5 33 0
Output
61題意:將一個長度為n的序列,分成k段長度為m的子序列,求這k個子序列和的最大值思路:dp[i][j]表示是前i個數選出j段的最大值,顯然有不選這個數,和考慮這個數的兩種情況。而考慮這個數的話,因為連續性也只會增加以這個數為結尾的m序列#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>typedef long long ll;using namespace std;const int maxn = 5100;ll num[maxn], sum[maxn], dp[maxn][maxn];ll n, m, k;int main() {cin >> n >> m >> k;for (int i = 1; i <= n; i++) {cin >> num[i];sum[i] = sum[i-1] + num[i];}for (int i = m; i <= n; i++)for (int j = k; j >= 1; j--)dp[i][j] = max(dp[i-1][j], dp[i-m][j-1]+sum[i]-sum[i-m]);cout << dp[n][k] << endl;return 0;}
Codeforces Round #267 (Div. 2) C. George and Job