George and Job

CodeForces - 467C

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.

Examples

Input
5 2 1
1 2 3 4 5
Output
9
Input
7 1 3
2 10 7 18 5 33 0
Output
61

sol:题意比较gou,用 K 条长度为 m 的不相交线段覆盖一段长度为 n 的数列,使得覆盖到的和最大
XJBdp应该不难,n2dp即可完美AC此题
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m,K;
ll Cost[N],Qzh[N];
ll dp[N][N];
int main()
{
int i,j;
R(n); R(m); R(K);
for(i=;i<=n;i++) R(Cost[i]);
for(i=;i<=n;i++) Qzh[i]=Qzh[i-]+Cost[i];
dp[][]=;
for(j=;j<=K;j++)
{
for(i=j*m;i<=n;i++)
{
dp[i][j]=max(dp[i-][j],dp[i-m][j-]+Qzh[i]-Qzh[i-m]);
}
}
Wl(dp[n][K]);
return ;
}
/*
Input
5 2 1
1 2 3 4 5
Output
9 Input
7 1 3
2 10 7 18 5 33 0
Output
61
*/
 

最新文章

  1. 一个简易的MysQL性能查询脚本
  2. get与post需要注意的几点
  3. .NET中的CTS、CLS和CLR
  4. HBase之计数器
  5. 从C#到Objective-C
  6. LeetCode——Path Sum II
  7. Mac OS X 安装后的简单设置
  8. 实验:企业级分布式存储应用与实战-mogilefs实现
  9. ajax异步的问题,(主要解决有时候前台打断点和不打断点结果不一样的问题,一般情况下是存在异步的问题)
  10. javaweb面试题
  11. 使用Eclipse来操作HDFS的文件
  12. Media Queries 媒体查询常见设备断点
  13. python - wmi模块学习(windwos硬件信息获取)
  14. c++字符串前几位,后几位的截取
  15. POJ - 2240 Arbitrage(Bellman-Ford)
  16. 世纪互联提供的关于Powershell中将虚拟机加入备份保管库的方法
  17. prometheus-dashboard-to-grafana
  18. Swift - 3.0 去掉 C 风格循环
  19. NERDTree基本使用教程
  20. 【BZOJ】1044: [HAOI2008]木棍分割(二分+dp)

热门文章

  1. [BZOJ 3709] Bohater
  2. [HNOI2019]多边形[二叉树建模、组合计数]
  3. 开源组件ELK日志系统配置与管理
  4. python知识点及面试面试大集合
  5. Ubuntu18.04安装netstat
  6. MariaDB 和 MySQL 比较
  7. 安全测试学习之bWAPP环境搭建
  8. Laravel 核心--Facades 门面
  9. pojo类自动生成序列化ID
  10. Git本地仓库push至GitHub远程仓库每次输入账户密码问题解决(亲测可行)