首页 > 代码库 > Codeforces Round #267 (Div. 2) C. George and Job
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 sequence of n integers p1,?p2,?...,?pn. You are to choosek pairs of integers:
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 1 1 2 3 4 5
Output
9
Input
7 1 3 2 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个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。