【题解】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 ...
随机推荐
- Linux基础学习3
鸟哥私房菜第十一章 read 用来读取键盘输入的变量,常被用在shell script的交互当中 [root@www ~]# read [-pt] variable 选项不参数: -p :后面可以 ...
- Jsp2.0自定义标签(第二天)——自定义循环标签
今天是学习自定义标签的第二天,主要是写一个自定义的循环标签. 先看效果图: 前台页面Jsp代码 <%@ page language="java" contentType=&q ...
- Netty4.0 用户指南
原文链接http://netty.io/wiki/user-guide-for-4.x.html 前言 Nowadays we use general purpose applications or ...
- Android--数据库数据显示至屏幕
MainActivity.java 这段代码的作用是从数据库中获取到数据并显示在界面上 import java.util.ArrayList; import java.util.List; impor ...
- linux过滤ip段
https://www.2cto.com/net/201307/227257.html
- vue2.0 仿手机新闻站(三)通过 vuex 进行状态管理
1.创建 store 结构 2.main.js 引入 vuex 3. App.vue 组件使用 vuex <template> <div id="app"&g ...
- html5,audio音乐播放器
最终,做了自己原来一直想要实现的事儿.得出的结果是,有些事儿一旦開始做了,那么它就并非非常难. 如今的我,正听着自己的播放器放出的<光辉岁月>写这篇周六清晨的博文.写的不是非常好.但也请各 ...
- apue学习笔记(第十五章 进程间通信)
本章将说明进程之间相互通信的其它技术----进程间通信(IPC) 管道 管道只能在具有公共祖先的两个进程之间只用.通常,一个管道由一个进程创建,在进程调用fork后,这个管道就能在父进程和子进程之间使 ...
- socket 、 udp 和 tcp
强调一点: socket . udp . tcp之间的区别. socket只是一种套接字,就是两台电脑两端的东西,中间传输以流的格式进行. IBEO好像是TCP/IP , 无论对于TCP和UDP, ...
- 对datatable进行linq过滤
实例: DataTable data = new DataTable(); data.Columns.Add("schoolid", Type.GetType("Syst ...