codeforces467C
George and Job
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.
Input
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).
Output
Print an integer in a single line — the maximum possible value of sum.
Examples
5 2 1
1 2 3 4 5
9
7 1 3
2 10 7 18 5 33 0
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的更多相关文章
随机推荐
- WCF无.SVC文件服务激活,及不添加服务引用调用WCF
一,新建WCF服务引用程序 1,删除.svc文件,全部删除. 2,新建 IService 类 namespace TestWcf { [ServiceContract] public interfac ...
- 实时监控input输入值变化
在web开发中,我们有时会需要动态监听输入框值的变化,当使用onkeydown.onkeypress.onkeyup作为监听事件时,会发现一些复制粘贴等操作用不了,同时,在处理组合快键键的时候也很麻烦 ...
- Linux下快速配置Java开发环境
1.下载 jdk8官网下载地址 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html ...
- 【C#复习总结】细说 Lambda表达式
1 前言 本系列会将[委托] [匿名方法][Lambda表达式] [泛型委托] [表达式树] [事件]等基础知识总结一下.(本人小白一枚,有错误的地方希望大佬指正) 系类1:细说委托 系类2:细说匿名 ...
- 未安装Oracle客户端的服务器上,使用ASP.NET远程连接Oracle
公司服务器一直都是使用 .NET+SQLSERVER的开发方式,有个项目需要进行读取远程Oracle的需求.由于oracle 基本不会,也是一边做一遍摸索. 首先是使用工具测试是否已经联通,因为之前用 ...
- vue开发中regeneratorRuntime is not defined
我的项目是用vue提供的vue-cil脚手架生成的项目,但是当我在项目中使用async/await,编译代码的的时候报了regeneratorRuntime is not defined的错,我查过资 ...
- 七、Json格式的对象都可以通过遍历来获得里面的value值
- Leetcode 26. Remove Duplicates from Sorted Array (easy)
Given a sorted array, remove the duplicates in-place such that each element appear only once and ret ...
- H5 62-浮动元素字围现象
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- struts2的基本使用
struts2在web中当作前端控制器,接收来自页面的请求,使用过滤器拦截模式对请求进行拦截并交给相应配置的action类处理. 所以在web中使用最重要的是struts2的核心过滤器StrutsPr ...