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. django加载静态文件

    在一个网页中,不仅仅只有一个 html 骨架,还需要 css 样式文件. js 执行文件以及一些图片等,因此在 DTL 中加载静态文件是一个必须要解决的问题.在 DTL 中,使用 static 标签来 ...

  2. Bitbucket备份恢复

    我们需要备份什么? home directory:contains  repository data, log files, plugins, and so on. database:contains ...

  3. PHP命名空间(Namespace)的使用简介

    原文链接:https://www.cnblogs.com/zhouguowei/p/5200878.html 可以导入命名空间也可以导入命名空间的类 <?php namespace Blog\A ...

  4. C语言实现随机生成0~100的数

    #include <iostream> #include <time.h> int main() { srand((unsigned)time(NULL));//srand() ...

  5. git给log设置别名来快速查看友好的log信息

    把lg配置成了:git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(y ...

  6. ubuntu upgrade

    升级命令 虽然 apt-get 经常被人诟病,但实际上它还是个挺好用的软件包管理器.在 Ubuntu 14.04 以后的系统中,apt-get 相关的升级更新命令有四个: apt-get update ...

  7. rocketmq总结(消息的顺序、重复、事务、消费模式)

    rocketmq总结(消息的顺序.重复.事务.消费模式) 参考: http://www.cnblogs.com/wxd0108/p/6038543.html https://www.cnblogs.c ...

  8. hihoCoder week12 刷油漆

    题目链接: https://hihocoder.com/contest/hiho12/problem/1 给出一棵树 每个节点的价值 求以1为根的树中,选取m个相联通的节点的最大价值和 #includ ...

  9. java 安装环境 疑问(1)

    java安装时有看到javaEE的 sdk 和 javaSE的jdk,这一点查一下资料,一般时安装jdk就好了

  10. 论文笔记:Variational Capsules for Image Analysis and Synthesis

    Variational Capsules for Image Analysis and Synthesis  2018-07-16 16:54:36 Paper: https://arxiv.org/ ...