DP....

C. George and Job
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 ≤ 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 nm 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 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

/**
* Created by ckboss on 14-9-19.
*/
import java.util.*; public class GeorgeandJob {
static int n,m,k;
static long[] a = new long[5050];
static long[] sum = new long[5050];
static long[][] dp = new long[5050][3];
public static void main(String[] args){
Scanner in = new Scanner(System.in);
n=in.nextInt(); m=in.nextInt(); k=in.nextInt();
for(int i=1;i<=n;i++){
a[i]=in.nextInt();
sum[i]=sum[i-1]+a[i];
}
for(int i=m;i<=n;i++){
dp[i][1]=Math.max(dp[i-1][1],sum[i]-sum[i-m]);
}
for(int j=2;j<=k;j++){
for(int i=j*m;i<=n;i++){
dp[i][j%2]=Math.max(dp[i-m][(j-1)%2]+sum[i]-sum[i-m],dp[i-1][j%2]);
}
}
long ans=0;
for(int i=k*m;i<=n;i++){
ans=Math.max(ans,dp[i][k%2]);
}
System.out.println(ans);
}
}

Codeforces 467C. George and Job的更多相关文章

  1. Codeforces 467C George and Job(DP)

    题目 Source http://codeforces.com/contest/467/problem/C Description The new ITone 6 has been released ...

  2. codeforces 467C.George and Job 解题报告

    题目链接:http://codeforces.com/problemset/problem/467/C 题目意思:给出一条含有 n 个数的序列,需要从中找出 k 对,每对长度为 m 的子序列,使得 找 ...

  3. Codeforces 467C. George and Job (dp)

    题目链接:http://codeforces.com/contest/467/problem/C 求k个不重叠长m的连续子序列的最大和. dp[i][j]表示第i个数的位置个序列的最大和. 前缀和一下 ...

  4. 【题解】codeforces 467C George and Job dp

    题目描述 新款手机 iTone6 近期上市,George 很想买一只.不幸地,George 没有足够的钱,所以 George 打算当一名程序猿去打工.现在George遇到了一个问题. 给出一组有 n ...

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

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

  6. 【Codeforces 467C】George and Job

    [链接] 我是链接,点我呀:) [题意] 让你从1..n这n个数字中 选出来k个不相交的长度为m的区间 然后这个k个区间的和最大 求出这k个区间的和的最大值 [题解] 设dp[i][j]表示前i个数字 ...

  7. codeforces B. George and Round 解题报告

    题目链接:http://codeforces.com/contest/387/problem/B 题目意思:给出1-n个问题,以及要满足是good rounde条件下这n个问题分别需要达到的compl ...

  8. Codeforces 387E George and Cards

    George and Cards 我们找到每个要被删的数字左边和右边第一个比它小的没被删的数字的位置.然后从小到大枚举要被删的数, 求答案. #include<bits/stdc++.h> ...

  9. codeforces 387C George and Number

    这道题目的意思是对于每个要删除的数字,向前或向后找到一块连续的数字,而它是其中最小的: 很容易看出对于所有要先删除的数字要从大到小删除: 然后对于每个要删除的字母,要找到比他小的,但是在原数列中又靠它 ...

随机推荐

  1. passwd---设置用户密码的相关信息

    passwd命令   passwd命令用于设置用户的认证信息,包括用户密码.密码过期时间等.系统管理者则能用它管理系统用户的密码.只有管理者可以指定用户名称,一般用户只能变更自己的密码. 语法 pas ...

  2. RK3066 实现LED闪烁的代码分析

    实现LED灯的闪烁,须要在驱动里加入一个定时器函数,详细实现涉及到了LED GPIO驱动.用户空间程序调用驱动程序. 1.首先来看LED设备驱动注冊过程,代码位于../kernel/drivers/l ...

  3. Word Ladder II [leetcode]

    本题有几个注意点: 1. 回溯找路径时.依据路径的最大长度控制回溯深度 2. BFS时,在找到end单词后,给当前层做标记find=true,遍历完当前层后结束.不须要遍历下一层了. 3. 能够将字典 ...

  4. 进阶攻略|最全的前端开源JS框架和库

    新的 Javascript 库层出不穷,从而Web 社区愈发活跃.多样.在多方面快速发展.详细去描述每一种主流的 Javascript框架和库近乎不可能,所以在这篇文章中主要介绍一些对前端发展最具影响 ...

  5. 今天发现里一个非常好用的Listbox自绘类,带不同文字字体和图片,觉得很有必要记下来

    代码简写 MyListBox.h class CUseListBox : public CListBox { typedef struct _ListBox_Data { CString strApp ...

  6. Spring学习总结(6)——Spring之核心容器bean

    一.Bean的基础知识 1.在xml配置文件中,bean的标识(id 和 name) id:指定在benafactory中管理该bean的唯一的标识.name可用来唯一标识bean 或给bean起别名 ...

  7. body{display:none}

    body{display:none} 使浏览器不显示内容,用这样的代码删除 $document = str_replace('body{display:none}','',$document);

  8. 第三次作业 201731082208 黄亚恒&肖莉

    Github项目地址:https://github.com/HYHSTUDEY/WordCount.git 作业地址:https://www.cnblogs.com/hyhhyh090628/p/10 ...

  9. sampleviewer add menu item error 'assert'

    可以跟踪到 mfc提供的源代码内部,(注:如果打开了mfc源代码,设置了断点,但是跟不进去,那就需要更新PDB文件,具体网上搜)打开 wincore.cpp文件(D:\Program Files\Mi ...

  10. Something-Summary

    1.Combinatorial Mathematics 1.1 Bell Number: \(B_n\)表示元素个数为n的集合划分成若干个不相交集合的方案数. \(B_{n + 1} = \sum_{ ...