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
  1. 5 2 1
  2. 1 2 3 4 5
output
  1. 9
input
  1. 7 1 3
  2. 2 10 7 18 5 33 0
output
  1. 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])

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<cmath>
  6. #define LL long long
  7. using namespace std;
  8. inline int read()
  9. {
  10. int x=0,f=1;char ch=getchar();
  11. while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
  12. while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
  13. return x*f;
  14. }
  15. int n,m,k;
  16. LL f[5010][5010];
  17. LL a[5010],s[5010],t[5010];
  18. int main()
  19. {
  20. n=read();m=read();k=read();
  21. for (int i=1;i<=n;i++)a[i]=read();
  22. for (int i=1;i<=n;i++)s[i]=s[i-1]+a[i];
  23. for (int i=m;i<=n;i++)
  24. t[i]=s[i]-s[i-m];
  25. for (int i=1;i<=k;i++)
  26. {
  27. for (int j=m;j<=n;j++)f[i][j]=max(f[i][j-1],f[i-1][j-m]+t[j]);
  28. }
  29. printf("%I64d",f[k][n]);
  30. }

  

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. Ajax 缓存问题

    Ajax通过GET方式请求服务器数据,Microsoft Internet Explorer浏览器下,由于缓存问题,读取的数据非最新数据,解决问题方法如下: function getData(url, ...

  2. ZOJ3516 (图的遍历)

    Tree of Three Time Limit: 2 Seconds      Memory Limit: 65536 KB Now we have a tree and some queries ...

  3. hdu 3681 Prison Break(状态压缩+bfs)

    Problem Description Rompire . Now it’s time to escape, but Micheal# needs an optimal plan and he con ...

  4. 解决红米等手机(移动端)无法触发touchend事件

    触屏事件的简单描述: js的触屏事件,主要有三个事件:touchstart,touchmove,touchend. 这三个事件最重要的属性是 pageX和 pageY,表示X坐标,Y坐标.touchs ...

  5. Photoshop 批量处理图片

    不论什么你想反复进行的操作都能够通过创建 Photoshop 批处理程序来完毕.比如.你想批量改变图片的大小,就能够通过下面操作来实现. 1.打开随意一张图片,在动作面板中,点击新建button 2. ...

  6. apache 限制指定user_agent

    有些user_agent 不是我们想要的,可以通过rewrite功能针对 %{HTTP_USER_AGENT} 来rewirete到404页,从而达到限制某些user_agent的请求.   配置如下 ...

  7. VLC播放器架构剖析

    VLC采用多线程并行解码架构,线程之间通过单独的一个线程控制所有线程的状态,解码器采用filter模式.组织方式为模块架构 模块简述:libvlc                  是VLC的核心部分 ...

  8. Android多项目依赖在Eclipse中无法关联源代码的问题解决 Ctril 点不进去的解决方法

    1. 使用快捷键:Ctrl+shift+R,在弹出框中输入.classpath  找到被作为library引入的那个.classpath文件. 2.将kind="src" path ...

  9. angular controller之间通信方式

    对于日常开发中,难免会有controller之间通信需求.对于controller之间通信有两种方式可以做到. 用 Angular 进行开发,基本上都会遇到 Controller 之间通信的问题,本文 ...

  10. 大数值基础、for与while循环的简单对比