Codeforces Round #267 (Div. 2) C. George and Job

來源:互聯網
上載者:User

標籤: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?≤?nri?-?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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.