C. 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.

Sample test(s)
 
input
5 2 1
1 2 3 4 5
output
9

题意:给出一个数字序列,要求找出k个m长度不相交的区间,且区间数字之和最大

题解:dp[i][j]表示:

dp:dp[j][i]=max(dp[j-m][i-1]+sum[j]-sum[j-m],dp[j-1][i]);

//зїеп:1085422276
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <typeinfo>
#include <map>
#include <stack>
typedef long long ll;
#define inf 100000000
#define mod 1000000007
using namespace std; inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//***************************************
ll sum[];
ll dp[][];
int main()
{
int n,m,k,a[];
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
sum[i]=sum[i-]+a[i];
}
for(int i=;i<=k;i++)
{
for(int j=i*m;j<=n;j++){
dp[j][i]=max(dp[j-m][i-]+sum[j]-sum[j-m],dp[j-][i]);
}
}
cout<<dp[n][k]<<endl;
return ;
}

代码

Codeforces Round #267 (Div. 2) C. George and Job DP的更多相关文章

  1. 01背包 Codeforces Round #267 (Div. 2) C. George and Job

    题目传送门 /* 题意:选择k个m长的区间,使得总和最大 01背包:dp[i][j] 表示在i的位置选或不选[i-m+1, i]这个区间,当它是第j个区间. 01背包思想,状态转移方程:dp[i][j ...

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

    Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...

  3. Codeforces Round #267 (Div. 2) C. George and Job (dp)

    wa哭了,,t哭了,,还是看了题解... 8170436                 2014-10-11 06:41:51     njczy2010     C - George and Jo ...

  4. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

  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 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 问题描述 ...

  7. Codeforces Round #267 (Div. 2) A

    题目: A. George and Accommodation time limit per test 1 second memory limit per test 256 megabytes inp ...

  8. Codeforces Round #267 (Div. 2) B. Fedor and New Game【位运算/给你m+1个数让你判断所给数的二进制形式与第m+1个数不相同的位数是不是小于等于k,是的话就累计起来】

    After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play ...

  9. Codeforces Round #267 (Div. 2) B. Fedor and New Game

    After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play ...

随机推荐

  1. 新浪微博客户端(18)-集成下拉刷新控件UIRefreshControl

    HomeViewController.m - (void)setupPullToRefreshView { UIRefreshControl *refreshControl = [[UIRefresh ...

  2. 初步揭秘node.js中的事件

    当你学习node.js的时候,Events是一个非常重要的需要理解的事情.非常多的Node对象触发事件,你能在文档API中找到很多例子.但是关于如何写自己的事件和监听,你可能还不太清楚.如果你不了解, ...

  3. 使用Angular和Nodejs搭建聊天室

    一,利用Node搭建静态服务器 这个是这个项目的底层支撑部分.用来支持静态资源文件像html, css, gif, jpg, png, javascript, json, plain text等等静态 ...

  4. C# 跨线程访问或者设置UI线程控件的方法

    一.背景 在C#中,由于使用线程和调用UI的线程属于两个不同的线程,如果在线程中直接设置UI元素的属性,此时就会出现跨线程错误. 二.问题解决方法 使用控件自带的Invoke或者BeginInvoke ...

  5. zhx's contest (矩阵快速幂 + 数学推论)

    zhx's contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  6. Scheme笔记(1)

    (define pi 3.14159) (define radius 10) (* pi (* radius radius)) (define circumference (* 2 pi radius ...

  7. HDU 4925 Apple Tree(模拟题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 解题报告:给你n*m的土地,现在对每一块土地有两种操作,最多只能在每块土地上进行两种操作,第一种 ...

  8. 十条nmap常用的扫描命令

    NMap也就是Network Mapper,nmap是在网络安全渗透测试中经常会用到的强大的扫描器,功能之强大,不言而喻.下面介绍一下它的几种扫描命令.具体的还是得靠大家自己学习,因为实在太强大了. ...

  9. ssh和mvc理论基础

    ssh中mvc到底指的什么 mvcsshhibernatespringstrutsioc在SSH整合的架构中,Spring充当了一个容器的作用,Spring使用IOC和AOP技术接管了Hibernat ...

  10. SVN安装与配置 SVN整合MyEclipse

    SVN安装: 1.安装服务器 ######### 安装文件:SVN服务器############### # http://www.collab.net/downloads/subversion # C ...