F2 - Pictures with Kittens (hard version)

思路:

单调队列优化dp

代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 5e3 + ;
const LL INF = 0x3f3f3f3f3f3f3f3f;
int a[N];
deque<pair<int, LL>> dp[N];
LL tmp[N];
int main() {
int n, k, x;
scanf("%d %d %d", &n, &k, &x);
for (int i = ; i <= n; i++) scanf("%d", &a[i]); dp[].pb({, });
for (int i = ; i <= n; i++) {
// i-k
for (int l = ; l <= x; l++) {
while(!dp[l-].empty() && dp[l-].front().fi < i-k) dp[l-].pop_front();
if(!dp[l-].empty()) tmp[l] = dp[l-].front().se + a[i];
} for (int l = ; l <= x; l++) {
while(!dp[l].empty() && dp[l].back().se <= tmp[l]) dp[l].pop_back();
if(tmp[l])dp[l].push_back({i, tmp[l]});
tmp[l] = ;
}
}
LL ans = -;
while(!dp[x].empty() && dp[x].front().fi <= n-k) dp[x].pop_front();
if(!dp[x].empty()) ans = dp[x].front().se;
printf("%lld\n", ans);
return ;
}

Codeforces 1077 F2 - Pictures with Kittens (hard version)的更多相关文章

  1. dp 优化 F2. Pictures with Kittens (hard version)

    dp的优化可能是自己的弱项吧 F1中n*n*n的复杂度强行过去了 F2就无能为力了: 状态转移 dp[ i ] [ j ] 第一个i存的是位置 1-n;    j是放入数字的个数 然后F1就暴力过去了 ...

  2. Codeforces Round #521 (Div. 3) F1. Pictures with Kittens (easy version)

    F1. Pictures with Kittens (easy version) 题目链接:https://codeforces.com/contest/1077/problem/F1 题意: 给出n ...

  3. Codeforces 1077F2 Pictures with Kittens (hard version)(DP+单调队列优化)

    题目链接:Pictures with Kittens (hard version) 题意:给定n长度的数字序列ai,求从中选出x个满足任意k长度区间都至少有一个被选到的最大和. 题解:数据量5000, ...

  4. Codeforces 1077F1 Pictures with Kittens (easy version)(DP)

    题目链接:Pictures with Kittens (easy version) 题意:给定n长度的数字序列ai,求从中选出x个满足任意k长度区间都至少有一个被选到的最大和. 题解:$dp[i][j ...

  5. Codeforces Round #535 E2-Array and Segments (Hard version)

    Codeforces Round #535 E2-Array and Segments (Hard version) 题意: 给你一个数列和一些区间,让你选择一些区间(选择的区间中的数都减一), 求最 ...

  6. codeforces 1165F1/F2 二分好题

    Codeforces 1165F1/F2 二分好题 传送门:https://codeforces.com/contest/1165/problem/F2 题意: 有n种物品,你对于第i个物品,你需要买 ...

  7. codeforces#1165 F2. Microtransactions (hard version) (二分+贪心)

    题目链接: https://codeforces.com/contest/1165/problem/F2 题意: 需要买$n$种物品,每种物品$k_i$个,每个物品需要两个硬币 每天获得一个硬币 有$ ...

  8. codeforces 1077F2. Pictures with Kittens (hard version)单调队列+dp

    被队友催着上(xun)分(lian),div3挑战一场蓝,大号给基佬紫了,结果从D开始他开始疯狂教我做人??表演如何AKdiv3???? 比赛场上:A 2 分钟,B题蜜汁乱计数,结果想得绕进去了20多 ...

  9. Codeforces 1077(F1+F2) DP 单调队列

    题意:给你一个n个元素的数组,从中选取x个元素,并且要保证任意的m个位置中必须至少有一个元素被选中,问选中元素的和最大可以是多少? F1 n,m,x到200 F2 n,m,x到5000. 思路1:设d ...

随机推荐

  1. Redis热点Key发现及常见解决方案!

    一.热点Key问题产生的原因 1.用户消费的数据远大于生产的数据(热卖商品.热点新闻.热点评论.明星直播). 在日常工作生活中一些突发的的事件,例如:双十一期间某些热门商品的降价促销,当这其中的某一件 ...

  2. linux homebrew skill 技巧

    $ cat /usr/bin/gitdiffH0#!/bin/bashgit diff HEAD $(git ls-files| grep '\.py$\|\.py\.in$') | osflake8 ...

  3. 记一次gitlab添加用户收不到邮件的解决办法

    之前再gitlab服务器上创建账号可以正常收到邮件,最近就收不到,查了gitlab的配置以及postfix服务都没有问题,后来查看了发信25端口,发现该25端口并没有开启(postfix已经开启),提 ...

  4. 20145320 《网络渗透》MSF基础应用

    20145320 <网络渗透>MSF基础应用 1.实验后回答问题 exploit 攻击模块,利用发现的安全漏洞或配置弱点对远程目标系统进行攻击.主要分为主动攻击和被动攻击.像我们这次做的实 ...

  5. echarts自定义图例legend文字和样式

    话不多说,先上效果图. 要完成这个图并不难,主要是下面那个图例比较难,需要定制. 让我们从官方文档找找思路,官方文档关于legend.formatter是这样的:链接在这 难点在于: 1.这里的图例文 ...

  6. 使用vim打造自己的python编辑器

    基础配置 vim的配置是在用户主目录下的 ~/.vimrc 文件中完成的,如果没有的话,需要自己新建一下: cd ~ touch .vimrc 首先做些简单的配置: set nocompatible ...

  7. Ubuntu + CUDA9 + CUDNN7 + OpenCV3.4 + contrib +CAFFE-master

    安装ubuntu时赞美Rufus(建议ubuntu16.04.04),过程参考 https://www.cnblogs.com/willnote/p/6725594.html 安 装 前 一 定 要 ...

  8. js的原型prototype究竟是什么?

    Javascript也是面向对象的语言,但它是一种基于原型Prototype的语言,而不是基于类的语言.在Javascript中,类和对象看起来没有太多的区别. 1.什么是prototype: fun ...

  9. Git 收集别名

    .gitconfig文件夹一般是在C:\Users\Administrator路径下,用于全局的git的配置 下面是git别名的设置: [alias] last = log -1 --stat a = ...

  10. Learning to Compare Image Patches via Convolutional Neural Networks --- Reading Summary

    Learning to Compare Image Patches via Convolutional Neural Networks ---  Reading Summary 2017.03.08 ...