题意略。

这个题目我开始题意理解得有点问题。本题的实质是在这个数列中选择一些数字,使得选出的这些数字之和最大,用dp来解。

我们先要明确:当我选择数列长度为2 * c时,不如把这个长度为2 * c的劈成两个c,这样对答案的贡献更大一些。

定义dp[i]为我在[i,n]中可谋取的最大贡献。

dp[i] = max{dp[k]} + earn[i,i + c - 1] (i + c <= k <= n - c - 1)。

可用单调队列优化。

详见代码:

#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
typedef long long LL; LL ai[maxn],dp[maxn];
LL st[maxn][],mm[maxn];
int que[maxn],head,tail,n,c; void init(){
mm[] = -;
for(int i = ;i < maxn;++i){
mm[i] = (i & (i - )) == ? mm[i - ] + : mm[i - ];
}
}
void init_rmq(){
for(int i = ;i <= n;++i) st[i][] = ai[i];
for(int j = ;j <= mm[n];++j){
for(int i = ;i + (<<j) - <= n;++i){
st[i][j] = min(st[i][j - ],st[i + (<<(j - ))][j - ]);
}
}
}
LL rmq(int l,int r){
LL k = mm[r - l + ];
return min(st[l][k],st[r - (<<k) + ][k]);
} int main(){
init();
while(scanf("%d%d",&n,&c) == ){
LL sum = ;
for(int i = ;i <= n;++i){
scanf("%lld",&ai[i]);
sum += ai[i];
}
init_rmq();
memset(dp,,sizeof(dp));
head = tail = ;
LL ans = ;
for(int i = n - c + ;i >= ;--i){
dp[i] = dp[que[head]] + rmq(i,i + c - );
ans = max(ans,dp[i]);
while(head < tail && dp[que[tail - ]] < dp[i + c - ]) --tail;
que[tail++] = i + c - ;
}
printf("%lld\n",sum - ans);
}
return ;
}

CodeForces 940E的更多相关文章

  1. CodeForces - 940E - Cashback +贪心+DP

    传送门:CodeForces - 940E - Cashback 题意:在一个长度为n的数组中,可以分出长度为 k 连续的多个数组b(每个数组 b 的 k 可不相同),然后,可以对每个数组 b 进行删 ...

  2. [Codeforces 940E]Cashback

    Description 题库链接 给你两个整数 \(n,c\) ,以及一个数列 \(A\) ,让你将序列分为许多段.对于每一段,他的价值为序列内除了最小的 \(\left\lfloor\frac{le ...

  3. 2018.12.29 codeforces 940E. Cashback(线性dp)

    传送门 题意:给出一个nnn个数的序列,要求将序列分成若干段,对于一段长度为kkk的自动删去最小的⌊kc⌋\left \lfloor \frac{k}{c} \right \rfloor⌊ck​⌋个数 ...

  4. Codeforces Round #466 (Div. 2) Solution

    从这里开始 题目列表 小结 Problem A Points on the line Problem B Our Tanya is Crying Out Loud Problem C Phone Nu ...

  5. DP刷题记录

    目录 dp刷题记录 codeforces 706C codeforces 940E BZOJ3997 POJ2279 GYM102082B GYM102082D codeforces132C L3-0 ...

  6. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  7. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  8. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  9. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

随机推荐

  1. BZOJ 3091: 城市旅行 [LCT splay 期望]

    3091: 城市旅行 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1454  Solved: 483[Submit][Status][Discuss ...

  2. Mac 系统安装 oh my zsh

    先来张图感受一下: 安装oh my zsh: 1.克隆这个项目到本地(前提是你得有装git) git clone git://github.com/robbyrussell/oh-my-zsh.git ...

  3. python学习:猜数字游戏

    猜数字游戏   系统生成一个100以内的随机整数, 玩家有6次机会进行猜猜看,每次猜测都有反馈(猜大了,猜小了,猜对了-结束) 6次中,猜对了,玩家赢了. 否则系统赢了   #!/usr/bin/en ...

  4. 使用CentOS Linux Bridge搭建Vxlan环境

    一. 基础环境使用VmWare虚拟两台Linux机器.CentOS 7,Linux内核如下:4.5.3-1.el7.elrepo.x86_64如果内核版本太低,是不支持VxLan的.可以使用一下命令进 ...

  5. PHP 变量的实现原理

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica } p.p2 { margin: 0.0px 0.0px 0.0px 0. ...

  6. GNU autotools自动生成Makefile 介绍

    一.目的 使用autotools工具来帮助我们自动地生成符合自由软件惯例的makefile(这样就可以像常见的GNU程序一样,只要使用"./configure", "ma ...

  7. MySQL体系结构及多实例

    MySQL客户端和服务器端模型 MySQL是一个典型C/S,服务器端与客户端两部分组成 服务器端程序  mysqld mysql自带的客户端(mysql mysqladmin  mysqldump等) ...

  8. RHEL6误安装RHEL7的包导致glibc被升级后系统崩溃处理方法

    RHEL6误使用了RHEL7的光盘源,安装了某个RPM包之后,导致glibc被升级,进而导致系统崩溃.   [root@rhel65 ~]# yum install ftp Loaded plugin ...

  9. windows上nginx的安装和配置

    http://www.cnblogs.com/Li-Cheng/p/4399149.html http://www.cnblogs.com/huayangmeng/archive/2011/06/15 ...

  10. Codeforces785E - Anton and Permutation

    Portal Description 对一个长度为\(n(n\leq2\times10^5)\)的数列\(a\)进行\(m(m\leq5\times10^4)\)次操作,数列初始时为\(\{1,2,. ...