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 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 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 ...
随机推荐
- 【BZOJ-4008】亚瑟王 概率与期望 + DP
4008: [HNOI2015]亚瑟王 Time Limit: 20 Sec Memory Limit: 512 MBSec Special JudgeSubmit: 832 Solved: 5 ...
- BZOJ1178 [Apio2009]CONVENTION会议中心
本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转载请注明出处,侵权必究,保留最终解释权! Description Siruseri政府建造了 ...
- SQL Server在更改计算机名后的设置
把原来的账号删除 再添加现有的账号 添加权限 搞定了上面的账号配置,接下来就是设置服务器名称 参考:http://www.cnblogs.com/EasonJim/p/6114249.html 后话: ...
- Jenkins实现生产环境部署文件的回滚操作(Windows)
由于dotnet项目的生产环境环境部署工具比较少,所以我使用jenkins作为生产环境的自动化部署工具. 既然有回滚操作,那么就会有部署操作:要实现回滚,先要实现部署的操作,我在jenkins搭建了一 ...
- @EmbeddedId和@idClass的区别
@idClass 使复合主键类成为非嵌入类,使用 @IdClass 批注为实体指定一个复合主键类(通常由两个或更多基元类型或 JDK 对象类型组成).从原有数据库映射时(此时数据库键由多列组成),通常 ...
- Myeclipse 加载ojdbc14.jar步骤
目的:加载驱动程序,需要找到驱动的具体位置,就是找到其驱动的类名,Class.forName("oracle.jdbc.driver.OracleDriver");//加载并注册驱 ...
- Spring表单参数绑定中对“is”开头的boolean类型字段的的处理
之前在新浪微博上面发了一个微薄: 弱弱的发现在定义boolean类型的时候最好不要使用“is”开头,可以避免一些问题哦 然后有一些朋友朋友问我为什么,当时比较忙,现在写篇文章举一个例子,回复一下这个问 ...
- POJ 1061青蛙的约会(拓展欧几里德算法)
题目链接: 传送门 青蛙的约会 Time Limit: 1000MS Memory Limit: 65536K Description 两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见 ...
- python数据类型和字符串(三)
一.变量 变量声明变量 #!/usr/bin/env python age= gender1='male' gender2='female' 变量作用:保存状态(程序的运行本质是一系列状态的变化,变量 ...
- import_site
http://kfd.me/ https://google.kfd.me/webhp?newwindow=1&safe=active http://googlebridge.com/searc ...