思路:二分之后用dp去check就好啦。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define PLI pair<LL, int>
#define ull unsigned long long
using namespace std; const int N = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-; int n, a[N], mx[N], mn[N]; bool check(int x) {
if(a[] > x) return false;
mx[] = mn[] = a[];
for(int i = ; i < n; i++) {
if(x - a[i-] < a[i]) return false;
mx[i] = min(a[]-mn[i-], a[i]);
if(x-a[i-]-a[]+mx[i-] >= a[i]) mn[i] = ;
else mn[i] = a[i] - (x-a[i-]-a[]+mx[i-]);
}
int cnt = a[] + a[n-] - mx[n-];
return x - cnt >= a[n];
} int main() {
scanf("%d", &n);
for(int i = ; i <= n; i++)
scanf("%d", &a[i]);
if(n == ) printf("%d\n", a[]);
else if(n == ) printf("%d\n", a[]+a[]);
else {
int l = , r = , ans = ;
while(l <= r) {
int mid = l + r >> ;
if(check(mid)) r = mid - , ans = mid;
else l = mid + ;
}
printf("%d\n", ans);
}
return ;
} /*
*/

bzoj 1863 二分+dp check的更多相关文章

  1. BZOJ 1044 木棍分割 解题报告(二分+DP)

    来到机房刷了一道水(bian’tai)题.题目思想非常简单易懂(我的做法实际上参考了Evensgn 范学长,在此多谢范学长了) 题目摆上: 1044: [HAOI2008]木棍分割 Time Limi ...

  2. 二分+DP HDU 3433 A Task Process

    HDU 3433 A Task Process Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  3. Codeforces 660C - Hard Process - [二分+DP]

    题目链接:http://codeforces.com/problemset/problem/660/C 题意: 给你一个长度为 $n$ 的 $01$ 串 $a$,记 $f(a)$ 表示其中最长的一段连 ...

  4. 「学习笔记」wqs二分/dp凸优化

    [学习笔记]wqs二分/DP凸优化 从一个经典问题谈起: 有一个长度为 \(n\) 的序列 \(a\),要求找出恰好 \(k\) 个不相交的连续子序列,使得这 \(k\) 个序列的和最大 \(1 \l ...

  5. 洛谷$P4322\ [JSOI2016]$最佳团体 二分+$dp$

    正解:二分+$dp$ 解题报告: 传送门$QwQ$ 这题长得好套路嗷,,,就一看就看出来是个$01$分数规划+树形$dp$嘛$QwQ$. 考虑现在二分的值为$mid$,若$mid\leq as$,则有 ...

  6. 百度之星复赛 1004 / hdu5715 二分dp+trie

    XOR 游戏 Problem Description   众所周知,度度熊喜欢XOR运算[(XOR百科)](http://baike.baidu.com/view/674171.htm). 今天,它发 ...

  7. hdu 3433 A Task Process 二分+dp

    A Task Process Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  8. 2018.10.24 NOIP模拟 小 C 的数组(二分+dp)

    传送门 考试自己yyyyyy的乱搞的没过大样例二分+dp二分+dp二分+dp过了606060把我自己都吓到了! 这么说来乱搞跟被卡常的正解比只少101010分? 那我考场不打其他暴力想正解血亏啊. 正 ...

  9. 【bzoj1044】[HAOI2008]木棍分割 二分+dp

    题目描述 有n根木棍, 第i根木棍的长度为Li,n根木棍依次连结了一起, 总共有n-1个连接处. 现在允许你最多砍断m个连接处, 砍完后n根木棍被分成了很多段,要求满足总长度最大的一段长度最小, 并且 ...

随机推荐

  1. java io读写文件

    java io读写文件相关阅读:http://www.cnblogs.com/wing011203/archive/2013/05/03/3056535.html public class DemoI ...

  2. 【数据库-MySql】清空所有表格的所有数据

    方式一. drop procedure if exists del_all_tb; delimiter $$ create procedure del_all_tb(db char(20)) begi ...

  3. SQL语句(二十)—— 数据库安全性

    数据库安全性 1. SQL Server 配置管理器  => 网络配置 MSSQLSERVER 协议,如果应用程序和SQL Server 在同一机器上,仅使用 Shared Memory (共享 ...

  4. 流媒体技术学习笔记之(十六)H264编码profile & level控制

    H.264有四种画质级别,分别是baseline, extended, main, high: 1.Baseline Profile:基本画质.支持I/P 帧,只支持无交错(Progressive)和 ...

  5. IE6下面的css调试工具

    在开发过程中,代码部分实现之后,就要着手于前台展示部分的界面,公司的美工又是新手,无奈,只有自己慢慢调了,但IE6之前的版本都没有好的调试工具,后来在网上搜索了一个 IE Developer Tool ...

  6. HDU 1535 Invitation Cards (最短路)

    题目链接 Problem Description In the age of television, not many people attend theater performances. Anti ...

  7. 【译】第十一篇 Integration Services:日志记录

    本篇文章是Integration Services系列的第十一篇,详细内容请参考原文. 简介在前一篇,我们讨论了事件行为.我们分享了操纵事件冒泡默认行为的方法,介绍了父子模式.在这一篇,我们会配置SS ...

  8. 最小生成树 kuangbin专题最后一个题

    题目链接:https://cn.vjudge.net/contest/66965#problem/N 注释:这道题需要用krustra,用prim的话可能会超时.并且在计算距离的时候要尽量减少步骤,具 ...

  9. python基础之命名空间

    前言 命名空间通俗的理解就是对象或变量的作用范围,在python中分为局部命令空间.模块命名空间和build-in全局命名空间. 局部命名空间 局部命名空间即在一个函数或一个类中起作用的变量或引用的字 ...

  10. Find Minimum in Rotated Sorted Array I & II

    Find Minimum in Rotated Sorted Array I Suppose a sorted array is rotated at some pivot unknown to yo ...