【题解】Painting Fence
【题解】Painting Fence
分治模板。贪心加分治。直接\(O(n^2logn)\)分治过去。考虑一块联通的柱形是子问题的,是递归的,贪心分治就可。记得对\(r-l+1\)取\(min\)。
上好看的代码
#include<bits/stdc++.h>
#define RP(t,a,b) for(register int (t)=(a),edd_=(b);t<=edd_;++t)
#define DRP(t,a,b) for(register int (t)=(a),edd_=(b);t>=edd_;--t)
#define ERP(t,a) for(int t=head[a];t;t=e[t].nx)
#define pushup(x) seg[(x)]=seg[(x)<<1]+seg[(x)<<1|1]
#define midd register int mid=(l+r)>>1
#define TMP template<class ccf>
#define rgt L,R,mid,r,pos<<1|1
#define lef L,R,l,mid,pos<<1
#define all 1,n,1
using namespace std;typedef long long ll;
TMP inline ccf Max(ccf a,ccf b){return a<b?b:a;}
TMP inline ccf Min(ccf a,ccf b){return a<b?a:b;}
TMP inline ccf Abs(ccf a){return a<0?-a:a;}
TMP inline ccf qr(ccf k){
char c=getchar();ccf x=0;int q=1;
while(c<48||c>57)q=c==45?-1:q,c=getchar();
while(c>=48&&c<=57)x=x*10+c-48,c=getchar();
return q==-1?-x:x;}
//-------------template&IO---------------------
const int maxn=5e3+15;
const int inf=2e9+5;
int data[maxn],n;
int divd(int l,int r,int cut){
if(l>r) return 0;
register int sav=inf,L=l,ret=0;
RP(t,l,r) if(data[t]-cut>0&&sav>data[t]-cut) sav=data[t]-cut;
RP(t,l,r+1) if(data[t]-cut-sav<=0||t>r) ret+=divd(L,t-1,cut+sav),L=t+1;
return Min(sav+ret,r-l+1);
}
int main(){
#ifndef ONLINE_JUDGE
freopen("color.in","r",stdin);
freopen("color.out","w",stdout);
#endif
n=qr(1);RP(t,1,n)data[t]=qr(1);
cout<<divd(1,n,0)<<endl;
return 0;
}
【题解】Painting Fence的更多相关文章
- CF448C Painting Fence (分治递归)
Codeforces Round #256 (Div. 2) C C. Painting Fence time limit per test 1 second memory limit per tes ...
- Codeforces Round #256 (Div. 2) C. Painting Fence 或搜索DP
C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard in ...
- Codeforces Round #256 (Div. 2) C. Painting Fence
C. Painting Fence Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Ch ...
- codeforces 256 div2 C. Painting Fence 分治
C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard in ...
- Codeforces Round #256 (Div. 2) C. Painting Fence(分治贪心)
题目链接:http://codeforces.com/problemset/problem/448/C C. Painting Fence time limit per test 1 second m ...
- Codeforces 448 C. Painting Fence
递归.分治. . . C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input ...
- Painting Fence
Painting Fence Time Limit:1000MS Memory Limit:524288KB 64bit IO Format:%I64d & %I64u Sub ...
- 【题解】Fence(单调队列)
[题解]Fence(单调队列) POJ - 1821 题目大意 有\(k\)个粉刷匠,每个粉刷匠一定要粉刷某个位置\(S_i\),一个粉刷匠可以粉刷至多\(l_i\)个位置(必须连续\(l_i\)互不 ...
- Codeforces 448C:Painting Fence 刷栅栏 超级好玩的一道题目
C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard in ...
随机推荐
- Maven项目管理工具初体验
在最前面声明,本文不涉及任何原理,只是对使用方法和期间遇到的问题如何解决.主要是随着年纪原来越大,越觉得好记星不如烂笔头的深意,同时如果能够帮助谁,那就最好不过了. 前两天自己做一个项目,然后好心朋友 ...
- SQL Server Debugging with WinDbg – an Introduction
Klaus Aschenbrenner Klaus Aschenbrenner provides independent SQL Server Consulting Services across E ...
- inux 下的/etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc 文件的作用
/etc/bashrc:为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取. ~/.bash_profile:每个用户都可使用该文件输入专用于自己使用的sh ...
- 【spring cloud】【spring boot】项目启动报错:Cannot determine embedded database driver class for database type NONE
解决参考文章:https://blog.csdn.net/hengyunabc/article/details/78762097 spring boot启动报错如下: Error starting A ...
- 真正解决 thinkphp 验证码 出错 无法显示 问题
今天做到验证码这一块想到tp自带验证图片 大喜单鼓捣半天不出来 一直是个小 X 官方提示:如果无法显示验证码,请检查:² PHP是否已经安装GD库支持:²输出之前是否有任何的输出(尤其是UTF8的B ...
- hdu254 DFS+BFS
这个题目需要注意以下几点: 1)注意界线问题,箱子和人不可以越界. 2)需要判断人是否可以到达人推箱子的指定位置. 3)不可以用箱子作为标记,因为箱子可以走原来走过的地方,我们用箱子和人推箱子的方向来 ...
- EasyMvc入门教程-基本控件说明(11)菜单导航
基本上,是个网站就会有菜单导航,目前流行的菜单是不是这样样子的? 似乎是bootstrap引领的风格,我们就用EasyMvc实现吧,上代码: @{ var data = new List<Men ...
- 未经处理的异常在 System.Data.dll 中发生。其它信息:在应使用条件的上下文(在 '***' 附近)中指定了非布尔类型的表达式。
机房收费系统中,有些人在联合查询这个模块用的是存储过程.我先尝试着在数据库中建立了一个视图.然后在UI层做个推断并生成查询条件strCondition. 在机房收费系统的"联合查询" ...
- Sublime3破解教程[转载]
sublime text 3 这个IDE相信很多人认识,尤其是python的.相对pycharm ide而言,速度快.界面清爽等优点,下面就分享下各个版本的破解方法 用UltraEdit等编辑器打开s ...
- DexClassLoader和PathClassLoader载入Dex流程
0x00 在上一篇文章apk安装和优化原理,在最后我们分析了DexClassLoader和PathClassLoader的构造函数的不同. PathClassLoader最后调用的是new DexFi ...