Codeforces 1077 F2 - Pictures with Kittens (hard version)
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)的更多相关文章
- dp 优化 F2. Pictures with Kittens (hard version)
dp的优化可能是自己的弱项吧 F1中n*n*n的复杂度强行过去了 F2就无能为力了: 状态转移 dp[ i ] [ j ] 第一个i存的是位置 1-n; j是放入数字的个数 然后F1就暴力过去了 ...
- 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 ...
- Codeforces 1077F2 Pictures with Kittens (hard version)(DP+单调队列优化)
题目链接:Pictures with Kittens (hard version) 题意:给定n长度的数字序列ai,求从中选出x个满足任意k长度区间都至少有一个被选到的最大和. 题解:数据量5000, ...
- Codeforces 1077F1 Pictures with Kittens (easy version)(DP)
题目链接:Pictures with Kittens (easy version) 题意:给定n长度的数字序列ai,求从中选出x个满足任意k长度区间都至少有一个被选到的最大和. 题解:$dp[i][j ...
- Codeforces Round #535 E2-Array and Segments (Hard version)
Codeforces Round #535 E2-Array and Segments (Hard version) 题意: 给你一个数列和一些区间,让你选择一些区间(选择的区间中的数都减一), 求最 ...
- codeforces 1165F1/F2 二分好题
Codeforces 1165F1/F2 二分好题 传送门:https://codeforces.com/contest/1165/problem/F2 题意: 有n种物品,你对于第i个物品,你需要买 ...
- codeforces#1165 F2. Microtransactions (hard version) (二分+贪心)
题目链接: https://codeforces.com/contest/1165/problem/F2 题意: 需要买$n$种物品,每种物品$k_i$个,每个物品需要两个硬币 每天获得一个硬币 有$ ...
- codeforces 1077F2. Pictures with Kittens (hard version)单调队列+dp
被队友催着上(xun)分(lian),div3挑战一场蓝,大号给基佬紫了,结果从D开始他开始疯狂教我做人??表演如何AKdiv3???? 比赛场上:A 2 分钟,B题蜜汁乱计数,结果想得绕进去了20多 ...
- Codeforces 1077(F1+F2) DP 单调队列
题意:给你一个n个元素的数组,从中选取x个元素,并且要保证任意的m个位置中必须至少有一个元素被选中,问选中元素的和最大可以是多少? F1 n,m,x到200 F2 n,m,x到5000. 思路1:设d ...
随机推荐
- android 颜色值参考,(有颜色图
) 2011-10-13 19:55:30| 分类: android | 标签:android颜色值|字号大中小 订阅 Android 常用RGB值以及中英文名称 颜 色 RGB值 英文名 中文名 ...
- phpstorm激活大全--持续更新(支持2018最新版)
方法一. 通过Licence Server 激活PHPStorm(快速) 方法原理是通过搭建服务器激活,不过网上有许多搭建好的. http://idea.goxz.gq http://v2mc.net ...
- RSD 直观介绍
RSD TOR RSD SLED Blade MEMORY REDFISH REDFISH with Storage IPMI https://yyscamper.gitbooks.io/the-wa ...
- 关于sql中in 和 exists 的效率问题
在用in的地方可以使用freemark标签代替,例如: 将 <#if assistantList??&& (assistantList?size > 0)> AND ...
- Linux系统PWM驱动【转】
本文转载自:https://blog.csdn.net/BorntoX/article/details/51879786 硬件平台:IMX6 内核版本:kernel3.0.35 在linux内核中有一 ...
- c# Database类的使用
参考资料http://ansonlh.iteye.com/blog/1689009 搜索:c# DatabaseFactory类
- 牛客OI周赛7-普及组 解题报告
出题人好评. 评测机差评. A 救救喵咪 二位偏序.如果数据范围大的话直接树状数组,不过才1000就\(O(n^2)\)暴力就ok了. #include <bits/stdc++.h> s ...
- IDEA创建Maven Web项目
简单介绍 本篇博客主要介绍使用IDEA如何创建Maven Web项目,具体是两个方面的内容:创建项目和配置tomcat服务器.前提是根据IDEA入门配置好了JDK及Maven. 创建项目 新建项目 填 ...
- Optical Flow related Tutorials
Optical Flow related Tutorials 2017-04-01 10:50:55 Reference: 1. http://blog.csdn.net/carson2005/art ...
- JQuery---高级类选择器
1.ContentFilters 1.1 语法:$('div:contains(edu)').css('backgroundColor','yellow'); 只看div 本身是否包含内容 1.2 语 ...