题目

Source

http://codeforces.com/contest/467/problem/C

Description

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 choose k pairs of integers:

[l1, 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 contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).

Output

Print an integer in a single line — the maximum possible value of sum.

Sample Input

5 2 1
1 2 3 4 5

7 1 3
2 10 7 18 5 33 0

Sample Output

9

61

分析

题目大概说给一个序列,求k个不重叠长m的连续子序列的最大和。

DP搞了。

  • dp[i][j]表示前i个数中构成j个子序列的最大和
  • 转移就是dp[i][j]=max(dp[i-1][j],dp[i-m][j-1]+sum[i]-sum[i-m]),sum是前缀和

代码

#include<cstdio>
#include<algorithm>
using namespace std;
long long d[5555][5555],sum[5555];
int a[5555];
int main(){
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
for(int i=1; i<=n; ++i) scanf("%d",a+i),sum[i]=sum[i-1]+a[i];
for(int i=1; i<=n; ++i){
for(int j=1; j<=k; ++j){
if(j*m>i) break;
d[i][j]=max(d[i-1][j],d[i-m][j-1]+sum[i]-sum[i-m]);
}
}
printf("%lld",d[n][k]);
return 0;
}

Codeforces 467C George and Job(DP)的更多相关文章

  1. CodeForces - 710E Generate a String (dp)

    题意:构造一个由a组成的串,如果插入或删除一个a,花费时间x,如果使当前串长度加倍,花费时间y,问要构造一个长度为n的串,最少花费多长时间. 分析:dp[i]---构造长度为i的串需要花费的最短时间. ...

  2. codeforces 467C George and Job(简单dp,看了题解抄一遍)

    题目 参考了网页:http://www.xue163.com/exploit/180/1802901.html //看了题解,抄了一遍,眼熟一下,增加一点熟练度 //dp[i][j]表示是前i个数选出 ...

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

    wa哭了,,t哭了,,还是看了题解... 8170436                 2014-10-11 06:41:51     njczy2010     C - George and Jo ...

  4. Codeforces Round #267 (Div. 2) C. George and Job(DP)补题

    Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...

  5. codeforces #267 C George and Job(DP)

    职务地址:http://codeforces.com/contest/467/problem/C 太弱了..这题当时都没做出来..思路是有的,可是自己出的几组数组总是过不去..今天又又一次写了一遍.才 ...

  6. 【Codeforces】CF 467 C George and Job(dp)

    题目 传送门:QWQ 分析 dp基础题. $ dp[i][j] $表示前i个数分成j组的最大和. 转移显然. 吐槽:做cf题全靠洛谷翻译苟活. 代码 #include <bits/stdc++. ...

  7. Educational Codeforces Round 51 D. Bicolorings(dp)

    https://codeforces.com/contest/1051/problem/D 题意 一个2*n的矩阵,你可以用黑白格子去填充他,求联通块数目等于k的方案数,答案%998244353. 思 ...

  8. Codeforces 536D - Tavas in Kansas(dp)

    Codeforces 题目传送门 & 洛谷题目传送门 其实这题本该 2019 年 12 月就 AC 的(详情请见 ycx 发此题题解的时间),然鹅鸽到了现在-- 首先以 \(s,t\) 分别为 ...

  9. CF467C George and Job (DP)

    Codeforces Round #267 (Div. 2) C. George and Job time limit per test 1 second memory limit per test ...

随机推荐

  1. W3C对DOM2.0定义的标准事件

    DOM2.0模型将事件处理流程分为三个阶段: 一.事件捕获阶段, 二.事件目标阶段, 三.事件起泡阶段. 具体如图(图片来源于网络,侵删) 事件捕获:当某个元素触发某个事件(如onclick),顶层对 ...

  2. mysql my.cnf配置文件详解

    本配置文件针对Dell R710,双至强E5620.16G内存的硬件配置.CentOS 5.6 64位系统,MySQL 5.5.x 稳定版.适用于日IP 50-100w,PV 100-300w的站点, ...

  3. Tomcat部署的时候 unpackWARs="true"

    在部署项目到Tomcat的时候发现当Tomcat启动的时候,项目并没有解压出来,导致系统传照片的时候找不到路径,因为,系统没有解压,所以找不到路径, 进入地址==>C:\Users\ceshi\ ...

  4. Java网络连接之HttpURLConnection 与 HttpClient

    HttpClient使用详解:http://blog.csdn.net/wangpeng047/article/details/19624529   注:HttpURLConnection输出流用ou ...

  5. sql中union和union all的用法

    如果我们需要将两个select语句的结果作为一个整体显示出来,我们就需要用到union或者union all关键字.union(或称为联合)的作用是将多个结果合并在一起显示出来. union和unio ...

  6. php的错误级别

    error_reporting() 用于设置 PHP 的报错级别并返回当前级别.(PHP 4, PHP 5) 函数能够在运行时设置 error_reporting 指令. PHP 有诸多错误级别,使用 ...

  7. IOS开发中有用的第三方库

    #Objective-C中最受瞩目库 [链接](https://github.com/languages​​/Objective-C/most_watched) * [three20](https:/ ...

  8. MVC – 4.mvc初体验(2)

    5.显示学员列表 效果 数据表 5.1 首先,在文件夹Models新建一个新建项(W),选择ADO.NET 实体数据模型 (SingleTest.edmx) 5.2 建一个控制器,StudentsCo ...

  9. jcaptcha组件小小改造解决Invalid ID, could not validate une

    https://my.oschina.net/chainlong/blog/192014

  10. Android Message Handling Mechanism

    转自:http://solarex.github.io/blog/2015/09/22/android-message-handling-mechanism/ Android is a message ...