题目

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. 让chrome的控制台更高大上(装B用)

    作为一名屌丝前端程序员,在装B的道路上是越走越远了!废话不多说,直接先上几张图:我的Element是这样的: 我的console是这个样子的: 我的Timeline是这个样子的: ---------- ...

  2. ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(七) 之 历史记录查询(时间,关键字,图片,文件),关键字高亮显示。

    前言 上一篇讲解了如何自定义右键菜单,都是前端的内容,本篇内容就一个:查询.聊天历史纪录查询,在之前介绍查找好友的那篇博客里已经提到过 Elasticsearch,今天它又要上场了.对于Elastic ...

  3. python基础——sorted()函数

    python基础——sorted()函数 排序算法 排序也是在程序中经常用到的算法.无论使用冒泡排序还是快速排序,排序的核心是比较两个元素的大小.如果是数字,我们可以直接比较,但如果是字符串或者两个d ...

  4. ArrayList 和 LinkedList 的区别

    1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构.2.对于随机访问get和set,ArrayList优于LinkedList,因为LinkedList要移动 ...

  5. 关于快捷键 Ctrl+Alt+[方向键] 的知识

    在用PS作图时使用 Ctrl+Alt+[方向键]  组合建时屏幕莫名翻转, 平时电脑懒得维护所以略卡,我不会说一般早上起床摁了开机去上完厕所回来还--咳咳 刚按下时瞬间一黑,再黑,,继续黑--真是大吃 ...

  6. Lattice 的 Framebuffer IP核使用调试笔记之datasheet笔记

    本文由远航路上ing 原创,转载请标明出处. 学习使用以及调试Framebuffer IP 核已经有一段时间了,调试的时候总想记录些东西,可是忙的时候就没有时间来写,只有先找个地方记录下,以后再总结. ...

  7. MVC - 17.OA项目

          1.分层   2.项目依赖关系 MODEL IDAL -> MODEL DAL -> IDAL,MODEL,EntityFramewrok(注意和MODEL里的版本要一致),S ...

  8. 【数据库】 防止sql注入,过滤敏感关键字

    private bool FilterIllegalChar(string sWord) { var result = false; var keyWord = @"select|inser ...

  9. 无废话ExtJs 入门教程二[Hello World]

    无废话ExtJs 入门教程二[Hello World] extjs技术交流,欢迎加群(201926085) 我们在学校里学习任何一门语言都是从"Hello World"开始,这里我 ...

  10. hdu 1075:What Are You Talking About(字典树,经典题,字典翻译)

    What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K ...