CF467C George and Job (DP)
Codeforces Round #267 (Div. 2)
C. George and Job
time limit per test
1 second memory limit per test
256 megabytes input
standard input output
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 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 Output
9 Input
7 1 3 Output
61 |
题意:
给出n,m,k,给出由n个数组成的序列,在其中选出k组不重叠的连续m个数,使选择的数的和最大。
题解:
DP。
f[i][j],表示在[1,i]中选了j个区间得到的最大的和。
由于要经常求某连续m个数的和,可以先预处理出所有连续m个数的和,sum[i]表示以i为结尾的连续m个数的和。
最后结果为f[n][k]。
状态转移:
mf1(f);///全部置为-1
FOR(i,,n) f[i][]=;
FOR(i,,n){
FOR(j,,k){
f[i][j]=f[i-][j];
if(i-m>= && f[i-m][j-] != -) f[i][j]=max(f[i][j],f[i-m][j-]+sum[i]);
}
}
全代码:
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define usll unsigned ll
#define mz(array) memset(array, 0, sizeof(array))
#define mf1(array) memset(array, -1, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) printf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("1biao.out","w",stdout)
#define mp make_pair
#define pb push_back
const double eps=1e-;
const double pi=acos(-1.0);
int a[];
ll sum[];
ll f[][];///f[i][j],到i时选了j个区间
int n,m,k;
int main(){
int i,j;
RD3(n,m,k);
FOR(i,,n){
RD(a[i]);
}
ll sm=;
FOR(i,,n){
sm+=a[i];
if(i>=m){
sum[i]=sm;
sm-=a[i-m+];
}
}
mf1(f);///全部置为-1
FOR(i,,n) f[i][]=;
FOR(i,,n){
FOR(j,,k){
f[i][j]=f[i-][j];
if(i-m>= && f[i-m][j-] != -) f[i][j]=max(f[i][j],f[i-m][j-]+sum[i]);
}
}
printf("%I64d\n",f[n][k]);
return ;
}
CF467C George and Job (DP)的更多相关文章
- Codeforces Round #267 (Div. 2) C. George and Job (dp)
wa哭了,,t哭了,,还是看了题解... 8170436 2014-10-11 06:41:51 njczy2010 C - George and Jo ...
- 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)补题
Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...
- codeforces #267 C George and Job(DP)
职务地址:http://codeforces.com/contest/467/problem/C 太弱了..这题当时都没做出来..思路是有的,可是自己出的几组数组总是过不去..今天又又一次写了一遍.才 ...
- 【Codeforces】CF 467 C George and Job(dp)
题目 传送门:QWQ 分析 dp基础题. $ dp[i][j] $表示前i个数分成j组的最大和. 转移显然. 吐槽:做cf题全靠洛谷翻译苟活. 代码 #include <bits/stdc++. ...
- LightOJ 1033 Generating Palindromes(dp)
LightOJ 1033 Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- lightOJ 1047 Neighbor House (DP)
lightOJ 1047 Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...
- UVA11125 - Arrange Some Marbles(dp)
UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
随机推荐
- 【bzoj2705】 SDOI2012—Longge的问题
http://www.lydsy.com/JudgeOnline/problem.php?id=2705 (题目链接) 题意 给定一个整数N,你需要求出∑gcd(i, N)(1<=i <= ...
- 洛谷P3398 仓鼠找sugar
题目描述 小仓鼠的和他的基(mei)友(zi)sugar住在地下洞穴中,每个节点的编号为1~n.地下洞穴是一个树形结构.这一天小仓鼠打算从从他的卧室(a)到餐厅(b),而他的基友同时要从他的卧室(c) ...
- 应用服务器Glassfish任意文件读取漏洞
catalogue . 前言和技术背景 . Glassfish安装配置 . 漏洞利用 . 漏洞缓解(修复) 1. 前言和技术背景 0x1: GlassFish是什么 GlassFish 是用于构建 J ...
- CentOS找回root密码
如果忘记了root密码,可以进入单用户模式进行密码重置. 重启系统,在grub的启动菜单中按下e键,然后编辑kernel那一行,在最后的quiet后加上single. 按下Enter后,再按b开机进入 ...
- Linux Command Line Basics
Most of this note comes from the Beginning the Linux Command Line, Second Edition by Sander van Vugt ...
- java 和 mysql 获取周 星期 的第一天 最后一天 或者 月的 日期(字符串转日期,日期转字符串,日期加减)
获取周的第一天,最后一天 System.out.println(getStartEndDate("2016-05-01", 1)); 获取星期的第一天和最后一天 System.ou ...
- JavaWeb学习总结-07 Filter 学习和使用
一 Filter简介 Filter也称之为过滤器,它是Servlet技术中最激动人心的技术,WEB开发人员通过Filter技术,对web服务器管理的所有web资源:例如Jsp, Servlet, 静态 ...
- [USACO2009 NOV GOLD]奶牛的图片
校内题,不给传送门了. 以前做完NOIp2013的火柴排队那道题后,当时很担心NOIp会出那种题,因为贪心的规则能不能看出来真的要看运气.但是这类题做多了后发现其实那道题的规则其实是很多题都已经用到了 ...
- CSS3的transition动画功能
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- 数组Arrays
1.toString 方法 Arrays的toString方法可以方便的输出一个数组的字符串形式,方便查看,它有九个重载的方法,包括八种基本类型数组和一个对象类型数组,这里列举两个: public s ...