Codeforces Round #267 (Div. 2) C. George and Job,
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 sequenceNIntegersP1, bytes,P2, middle..., middle ,...,PN. You are to chooseKPairs of integers:
[
L
1, bytes,R1], region [L2, bytes,R2], numbers..., numbers [LK, Bytes,RK] (1 limit ≤ limitL1 bytes ≤ bytesR1 worker <workerL2 bytes ≤ bytesR2 rows <values... rows <valuesLKLimit ≤ limitRKLimit ≤ limitN;RIAccept-Encoding-LIBytes + bytes 1 records = bytesM), Then ),
In such a way that the value of sum is maximal possible. Help George to interact with the task.
Input
The first line contains three integersN,MAndK(1 limit ≤ limit (MLimit × limitK) Bytes ≤ bytesNLimit ≤00005000). The second line containsNIntegersP1, bytes,P2, middle..., middle ,...,PN(0 bytes ≤ bytesPILimit ≤ limit 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. The idea of dividing a sequence with a length of n into sub-sequences with a k segment length of m to calculate the sum of the k sub-sequences is as follows: dp [I] [j] indicates the maximum value of the j segment selected by the number of I. Obviously, this number is not selected, and this number is considered. Considering this number, the continuity will only increase to the m sequence ending with this number.#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;}