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
这道题目的意思是对于每个要删除的数字,向前或向后找到一块连续的数字,而它是其中最小的: 很容易看出对于所有要先删除的数字要从大到小删除: 然后对于每个要删除的字母,要找到比他小的,但是在原数列中又靠它 ...
随机推荐
- 洛谷 P1256 显示图像
P1256 显示图像 题目描述 古老的显示屏是由N×M个像素(Pixel)点组成的.一个像素点的位置是根据所在行数和列数决定的.例如P(2,1)表示第2行第1列的像素点.那时候,屏幕只能显示黑与白两种 ...
- apache 使用 mod_fcgid.so模块时 配置指令
FcgidBusyScanInterval指令 说明:扫描繁忙超时进程的间隔 语法: FcgidBusyScanInterval seconds 默认:FcgidBusyScanInterval 12 ...
- poj 2480 Longge's problem 积性函数性质+欧拉函数
题意: 求f(n)=∑gcd(i, N) 1<=i <=N. 分析: f(n)是积性的数论上有证明(f(n)=sigma{1<=i<=N} gcd(i,N) = sigma{d ...
- 漫话C++之string字符串类的使用(有汇编分析)
C++中并不提倡继续使用C风格的字符串,而是为字符串定义了专门的类,名为string. 使用前的准备工作 在使用string类型时,需要包含string头文件,且string位于std命名空间内: # ...
- visibility-控件的显示跟隐藏设置
在Android开发中,大部分控件都有visibility这个属性,其属性有3个 visible:可见 invisible:不可见,但是会占据原来的位置 gone:不可见,也不会占据原来的位置 可见( ...
- int android.support.v7.widget.RecyclerView$ViewHolder.mItemViewType' on a null.....
Android.support.v7.widget.RecyclerView$ViewHolder.mItemViewType' on a null..空指针问题,费劲心思才找到报空指针的原因: 代码 ...
- monkey基础知识(二)
- Express简介、安装
Express 基于Node.js平台,快速.开放.极简的web开发框架,是目前最流行的基于Node.js的web开发框架,它提供一系列强大的功能,比如: 路由控制 参数获取 send和sendFil ...
- BZOJ2434: [Noi2011]阿狸的打字机(fail树+dfs序)
Description 阿狸喜欢收藏各种稀奇古怪的东西,最近他淘到一台老式的打字机.打字机上只有28个按键,分别印有26个小写英文字母和'B'.'P'两个字母. 经阿狸研究发现,这个打字机是这样工作的 ...
- UVa 11015 - 05-2 Rendezvous
題目:有一個班級的學生要一起寫作業,所以他們要到一個統一的地點.現在給你他們各自的位置, 問集合地點定在哪,能够讓全部人走的總路徑長度最小. 分析:圖論.最短路.直接利用Floyd計算最短路,找到和值 ...