Codeforces 467C. George and Job
DP....
1 second
256 megabytes
standard input
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 ≤ n; ri - li + 1 = m),
in such a way that the value of sum is
maximal possible. Help George to cope with the task.
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).
Print an integer in a single line — the maximum possible value of sum.
5 2 1
1 2 3 4 5
9
7 1 3
2 10 7 18 5 33 0
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的更多相关文章
- Codeforces 467C George and Job(DP)
题目 Source http://codeforces.com/contest/467/problem/C Description The new ITone 6 has been released ...
- codeforces 467C.George and Job 解题报告
题目链接:http://codeforces.com/problemset/problem/467/C 题目意思:给出一条含有 n 个数的序列,需要从中找出 k 对,每对长度为 m 的子序列,使得 找 ...
- Codeforces 467C. George and Job (dp)
题目链接:http://codeforces.com/contest/467/problem/C 求k个不重叠长m的连续子序列的最大和. dp[i][j]表示第i个数的位置个序列的最大和. 前缀和一下 ...
- 【题解】codeforces 467C George and Job dp
题目描述 新款手机 iTone6 近期上市,George 很想买一只.不幸地,George 没有足够的钱,所以 George 打算当一名程序猿去打工.现在George遇到了一个问题. 给出一组有 n ...
- codeforces 467C George and Job(简单dp,看了题解抄一遍)
题目 参考了网页:http://www.xue163.com/exploit/180/1802901.html //看了题解,抄了一遍,眼熟一下,增加一点熟练度 //dp[i][j]表示是前i个数选出 ...
- 【Codeforces 467C】George and Job
[链接] 我是链接,点我呀:) [题意] 让你从1..n这n个数字中 选出来k个不相交的长度为m的区间 然后这个k个区间的和最大 求出这k个区间的和的最大值 [题解] 设dp[i][j]表示前i个数字 ...
- codeforces B. George and Round 解题报告
题目链接:http://codeforces.com/contest/387/problem/B 题目意思:给出1-n个问题,以及要满足是good rounde条件下这n个问题分别需要达到的compl ...
- Codeforces 387E George and Cards
George and Cards 我们找到每个要被删的数字左边和右边第一个比它小的没被删的数字的位置.然后从小到大枚举要被删的数, 求答案. #include<bits/stdc++.h> ...
- codeforces 387C George and Number
这道题目的意思是对于每个要删除的数字,向前或向后找到一块连续的数字,而它是其中最小的: 很容易看出对于所有要先删除的数字要从大到小删除: 然后对于每个要删除的字母,要找到比他小的,但是在原数列中又靠它 ...
随机推荐
- atime&&mtime&&ctime区别
- Python datetime time 等时间 日期 之间的计算和相互转化
from datetime import datetime, date, timedelta, timezone from time import time, ctime, localtime, st ...
- 用node.js从零开始去写一个简单的爬虫
如果你不会Python语言,正好又是一个node.js小白,看完这篇文章之后,一定会觉得受益匪浅,感受到自己又新get到了一门技能,如何用node.js从零开始去写一个简单的爬虫,十分钟时间就能搞定, ...
- PatentTips - Improving security in a virtual machine host
BACKGROUND Computer viruses are a common problem for computer users. One typical mode of attack is t ...
- Windows 7 系统的旧版IE浏览器升级到IE11
Windows 7 系统的旧版IE浏览器升级到IE11 2016年1月12日微软全面停止对IE8.IE9.IE10浏览器的支持,不再提供安全服务,如果继续使用将会造成安全隐患,因此 Windows 7 ...
- scroll- 滑动条风格调整
<item name="scrollbarFadeDuration">250</item> <item name="scrollbarDef ...
- IAR FOR STM8 学习笔记 固件库 GPIO
经过一番挣扎,还是决定使用官方的固件库了.. 从网上下一个STM8S的固件库,记得是FOR IAR的. 找到里面的IAR模板就可以开始用了. 这些都是直接写好的库函数,可以直接调用,但首先得先读懂,先 ...
- canvas.toDataURL() gives “Security Error” in IE 11
http://stackoverflow.com/questions/30101143/canvas-todataurl-gives-security-error-in-ie-11
- 1.2 Use Cases中 Website Activity Tracking官网剖析(博主推荐)
不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Website Activity Tracking 网站活动追踪 The origi ...
- 软件——protel 的pcb电路图制作
近期一直在学习PCB板的绘制.