题意略。

这个题目我开始题意理解得有点问题。本题的实质是在这个数列中选择一些数字,使得选出的这些数字之和最大,用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. 发送邮件的小功能(.net core 版)

    前言: 使用.net core 开发有一段时间了,期间从.net core 2.0 preview1 到 preview2 又到core 1.1 现在2.0正式版出来了.又把项目升级至2.0了.目前正 ...

  2. 通过代码配置 Log4net来实现日志记录

    通过代码来创建配置文件,优点看起来更为简洁,不过还得看需求吧,之前我博客也写了一篇通过读取不同的配置文件还实现配置不同日志类型. //记录异常日志数据库连接字符串 private const stri ...

  3. spring使用中问题汇总

    1.配置文件找不到beans元素:可能是xsd与spring版本不一致,导致无法效验: 解决方案:将applicationContext.xml中xsd文件定义的版本改为spring jar包中定义的 ...

  4. qt中的事件机制

    事件 1.QEvent -->类型 -> QKeyEvent QEvent::KeyRelease QEvent::MouseMove -> QMouseEvent 2.事件处理过程 ...

  5. LeetCode - 690. Employee Importance

    You are given a data structure of employee information, which includes the employee's unique id, his ...

  6. jq实现碰到边缘反弹的动画

    先上效果图: 录出来有点卡顿的赶脚,实际上还是挺顺畅的. 1.HTML: <div class="box"></div> 2.CSS: body{ back ...

  7. 模板方法模式和JDBCTemplate(一)

    本篇博客的目录: 一:模板方法模式介绍 二:模板方法模式的简单实现 三:总结 一:模板方法模式的介绍 1.1:模板方法模式的定义 定义:一个操作中的算法的骨架,而将一些步骤延迟到子类中.Templat ...

  8. laravel框架学习-缓存,事件

    缓存配置:app/config/cache.php   缓存:     增加缓存项: Cache::put( 'key', 'value', $Cachetime );     在缓存中增加一个不存在 ...

  9. Install Centrifugo and quick start

    Install Centrifugo and quick start Go is a perfect language - it gives developers an opportunity to ...

  10. ps通道抠章

    1. 打开图片 2. 使用椭圆形选框工具,选择章所在范围(ALT+SHITF+鼠标左键) 3.复制图层(CTRL+J)为图层1,隐藏背景 4.进入通道,选择对比度最大的通道,复制通道副本 5.反选(C ...