【题解】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 ...
随机推荐
- Zabbix 企业Nginx监控
Zabbix监控Nginx状态 1 修改Nginx配置文件,开启Nginx监控 location /nginx_status { stub_status on; access_log off; all ...
- 深入SQL SERVER 2000的内存管理机制
http://www.cnblogs.com/softj/articles/243591.html
- 【iOS】Frame和Bounds的区别以及获取绝对坐标的办法
终于搞清楚了,UIView中的frame获取的是相对于所在ParentView的坐标,而bounds则是指UIView本身的坐标.比如下图(假设A是屏幕): View B的Frame坐标是指相对于Vi ...
- YOLO+yolo9000配置使用darknet
Installing Darknet 1.直接设置使用,编译通过 git clone https://github.com/pjreddie/darknet.git cd darknet make 2 ...
- centos7 下编译ffmpeg
下载包: wget https://ffmpeg.org/releases/ffmpeg-4.1.tar.gz GCC如果没有yasm: http://yasm.tortall.net/Downloa ...
- linux中read用法
read在while中的经常用法: root@ubuntu:/var/lib/logrotate :: # cat /etc/cron.daily/logrotate #!/bin/sh # Clea ...
- 【SharePoint】SharePoint 2013 使用PreSaveAction自定义客户端验证
使用PreSaveAction函数实现客户端自定义验证. 例:[项目编号]为空时,必须填写[责任者]项.(其中[项目编号]为单行文本框,[责任者]为用户/组选择框.) function PreSave ...
- hdu1394 Minimum Inversion Number(最小逆序数)
Minimum Inversion Number Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/O ...
- leetCode 95.Unique Binary Search Trees II (唯一二叉搜索树) 解题思路和方法
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...
- 把握linux内核设计思想(二):硬中断及中断处理
[版权声明:尊重原创.转载请保留出处:blog.csdn.net/shallnet,文章仅供学习交流,请勿用于商业用途] 操作系统负责管理硬件设备.为了使系统和硬件设备的协同工作不减少机器性能.系统和 ...