cf467C George and Job
1 second
256 megabytes
standard input
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 ≤ n; ri - li + 1 = m),
in such a way that the value of sum
is maximal possible. Help George to cope with the task.
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).
Print an integer in a single line — the maximum possible value of sum.
5 2 1
1 2 3 4 5
9
7 1 3
2 10 7 18 5 33 0
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])
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#define LL long long
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,m,k;
LL f[5010][5010];
LL a[5010],s[5010],t[5010];
int main()
{
n=read();m=read();k=read();
for (int i=1;i<=n;i++)a[i]=read();
for (int i=1;i<=n;i++)s[i]=s[i-1]+a[i];
for (int i=m;i<=n;i++)
t[i]=s[i]-s[i-m];
for (int i=1;i<=k;i++)
{
for (int j=m;j<=n;j++)f[i][j]=max(f[i][j-1],f[i-1][j-m]+t[j]);
}
printf("%I64d",f[k][n]);
}
cf467C George and Job的更多相关文章
- CF467C George and Job (DP)
Codeforces Round #267 (Div. 2) C. George and Job time limit per test 1 second memory limit per test ...
- [CF467C] George and Job - DP,前缀和
简单dp + 前缀和 你谷这乱标难度的风气真是-- #include <bits/stdc++.h> using namespace std; #define int long long ...
- CF467 AB 水题
Codeforces Round #267 (Div. 2) (C和D的题解单独写:CF467C George and Job (DP) CF467D Fedor and Essay 建图DFS) C ...
- CF习题集二
CF习题集二 一.CF507E Breaking Good 题目描述 \(Breaking Good\)这个游戏对于有经验的玩家来说也有一定的难度. 游戏的主角小明希望加入一个叫斧头帮的犯罪团伙.这个 ...
- 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 ...
- Codeforces 467C George and Job(DP)
题目 Source http://codeforces.com/contest/467/problem/C Description The new ITone 6 has been released ...
- Codeforces Round #267 (Div. 2) C. George and Job DP
C. George and Job The new ITone 6 has been released ...
- 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 问题描述 ...
- cf467A George and Accommodation
A. George and Accommodation time limit per test 1 second memory limit per test 256 megabytes input s ...
随机推荐
- hdu Hat's Fibonacci
import java.math.BigInteger; import java.util.*; public class Main { public static void main(String ...
- jQuery之动画效果
1.show()显示效果 语法:show(speed,callback) Number/String,Function speend为动画执行时间,单位为毫秒.也可以为slow"," ...
- Android实现自适应正方形GridView
Android实现自适应正方形GridView
- Intersection of Two Linked Lists 解答
Question Write a program to find the node at which the intersection of two singly linked lists begin ...
- 认识SVN
TortoiseSVN 是 Subversion 版本控制系统的一个免费开源客户端,可以超越时间的管理文件和目录.文件保存在中央版本库,除了能记住文件和目录的每次修改以外,版本库非常像普通的文件 服务 ...
- apache 开启压缩功能
apache如何开启压缩功能. 1,首先先确认是安装deflatte模块.如果未安装,可以重新编译apache添加参数--enable-deflate=shared ,或者扩展安装deflate模块, ...
- C#钩子应用实例
C#钩子应用实例一.写在最前 本文的内容只想以最通俗的语言说明钩子的使用方法,具体到钩子的详细介绍可以参照下面的网址: http://www.microsoft.com/china/community ...
- Java学习——static关键字
静态:static用法:是一个修饰符,用于修饰成员(成员变量或函数).当成员被静态修饰后,就多了一个调用方式,除了可以被对象调用外,还可以直接被类名调用.类名.静态成员 ststic特点:1, 随着类 ...
- HTML5 自定义属性 data-*介绍
在HTML5之前HTML4我们也可以自定义属性通过setAttribute去设置或者直接写在HTML标签里面那么HTML5新增data-*(*可以替换成你喜欢的任意名字)属性有什么用呢? 更便的捷操作 ...
- HDU 1051 - Rightmost Digit
找循环 #include <iostream> #include <cmath> using namespace std; int t,m,p,q; long long n; ...