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

我是sb……

一道水水的dp

f[i][j]表示前j个取i段的最大价值,t[i]表示从i-m+1到i的区间和

f[i][j]=max(f[i][j-1],f[i-1][j-m]+t[j])

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#define LL long long
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,m,k;
LL f[5010][5010];
LL a[5010],s[5010],t[5010];
int main()
{
n=read();m=read();k=read();
for (int i=1;i<=n;i++)a[i]=read();
for (int i=1;i<=n;i++)s[i]=s[i-1]+a[i];
for (int i=m;i<=n;i++)
t[i]=s[i]-s[i-m];
for (int i=1;i<=k;i++)
{
for (int j=m;j<=n;j++)f[i][j]=max(f[i][j-1],f[i-1][j-m]+t[j]);
}
printf("%I64d",f[k][n]);
}

  

cf467C George and Job的更多相关文章

  1. CF467C George and Job (DP)

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

  2. [CF467C] George and Job - DP,前缀和

    简单dp + 前缀和 你谷这乱标难度的风气真是-- #include <bits/stdc++.h> using namespace std; #define int long long ...

  3. CF467 AB 水题

    Codeforces Round #267 (Div. 2) (C和D的题解单独写:CF467C George and Job (DP) CF467D Fedor and Essay 建图DFS) C ...

  4. CF习题集二

    CF习题集二 一.CF507E Breaking Good 题目描述 \(Breaking Good\)这个游戏对于有经验的玩家来说也有一定的难度. 游戏的主角小明希望加入一个叫斧头帮的犯罪团伙.这个 ...

  5. Codeforces Round #227 (Div. 2) E. George and Cards set内二分+树状数组

    E. George and Cards   George is a cat, so he loves playing very much. Vitaly put n cards in a row in ...

  6. Codeforces 467C George and Job(DP)

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

  7. Codeforces Round #267 (Div. 2) C. George and Job DP

                                                  C. George and Job   The new ITone 6 has been released ...

  8. Codeforces Round #227 (Div. 2) E. George and Cards 线段树+set

    题目链接: 题目 E. George and Cards time limit per test:2 seconds memory limit per test:256 megabytes 问题描述 ...

  9. cf467A George and Accommodation

    A. George and Accommodation time limit per test 1 second memory limit per test 256 megabytes input s ...

随机推荐

  1. Keil C51 中指针的使用

    指针是C语言中比较难的一个内容,Keil C51在指针方面有和标准C不一样的地方,今天看了一些资料学习了一下Keil C51 中指针的使用. keil51的指针,包含两种指针:普通指针,兼容标准C:内 ...

  2. C#操作XML文档(XmlDocument、XmlNode、XmlAttribute、SelectSingleNode、SelectNodes、XmlNodeList)

    XML文档是一种通用的文档,这种文档既可以用.config作为后缀也可以用.xml作为后缀.XML文档主要由元素节点和节点的属性共同构成的.它有且仅有一个根节点,其他的节点全部都是根节点的子节点或者子 ...

  3. ZOJ3761(并查集+树的遍历)

    Easy billiards Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Edward think a g ...

  4. 监控父元素里面子元素内容变化 DOMSubtreeModified

    1监控ul的li的变化情况,并实时输出li的长度 布局: <ul id="isSelected"></ul> <span id="modal ...

  5. java打印菱形的简单方法

    代码: public class Diamond { /** * 测试main方法 */ public static void main(String[] args) { printDiamond(1 ...

  6. Java程序员面试题集(71-85)(转)

    转:http://blog.csdn.net/jackfrued/article/details/17566627 Java程序员面试题集(71-85) 摘要:这一部分主要包括了UML(统一建模语言) ...

  7. freemarker声明变量

    freemarker声明变量 1.使用assign创建和替换变量 (1)新建声明变量的ftl variable.ftl: <html> <head> <meta http ...

  8. nginx日志格式

    日志格式 log_format main '$remote_addr - $remote_user [$time_local] $request '                    '" ...

  9. 改变页面选择文字颜色和背景颜色----selection伪元素

    div::selection{color:#fff;background: #E83E84;text-shadow:none}  

  10. 解决ie6 闪动的问题

    /*解决ie6 闪动的问题*/ html,html body{_background-image:url(about:blank);_background-attachment:fixed}