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
*/
 

codeforces467C的更多相关文章

随机推荐

  1. 使用Git进行代码管理的心得--github for windows

    首先简述一下Git进行代码管理的情况 我使用的是github for windows,官网下载的速度太慢,所以用了离线安装包.安装之后会有GitHub和GitShell两个软件,其中Github采用图 ...

  2. React 系列 - 写出优雅的路由

    前言 自前端框架风靡以来,路由一词在前端的热度与日俱增,他是几乎所有前端框架的核心功能点.不同于后端,前端的路由往往需要表达更多的业务功能,例如与菜单耦合.与标题耦合.与"面包屑" ...

  3. *args **kwargs

    -----------耐得住寂寞,守得住芳华. # # -------------------------------[day10作业及默写]----------------------------- ...

  4. XGBoost模型的参数调优

    XGBoost算法在实际运行的过程中,可以通过以下要点进行参数调优: (1)添加正则项: 在模型参数中添加正则项,或加大正则项的惩罚力度,即通过调整加权参数,从而避免模型出现过拟合的情况. (2)控制 ...

  5. SDK安装详解以及adb的来源

    首先,下载Android SDK Tools,翻过墙的朋友可以去Google Android的官网上下载(http://developer.android.com/sdk/index.html) 选择 ...

  6. 合并dll文件

    在使用VS进行.Net编程时,出现了一个奇怪的现象. 在一个类库项目中导入了dll库A后,再导入A的两个依赖项(dll库)B和C,执行“生成”操作时,出现错误信息,提示B和C的库版本与A所需的不一致. ...

  7. 文件传输协议FTP、SFTP和SCP

    网络通信协议分层 应用层: HTTP(Hypertext Transfer Protocol 超文本传输协议,显示网页) DNS(Domain Name System) FTP(File Transf ...

  8. 硬盘扩容9999T

    win+r运行创建命令:subst H: d:\123说明:H指的是想要创建的盘符,d:\123是文件路径 删除命令subst H: d/说明 :H指的是已创建的盘符,/d指的是删除的意思 注意新盘符 ...

  9. Sigma Function

    做完这道题,我明白了人生的一个巨大道理,那就是: 其他题研究两下,做出来几百行.数论码字前研究半天,做出来十几二十行.做完特别没有成就感... 首先说下这题题意:首先,定义一个函数f[n],即为他所有 ...

  10. Eclipse在写java时的BUG

    要把这个关掉