【题解】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的更多相关文章

  1. CF448C Painting Fence (分治递归)

    Codeforces Round #256 (Div. 2) C C. Painting Fence time limit per test 1 second memory limit per tes ...

  2. 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 ...

  3. 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 ...

  4. codeforces 256 div2 C. Painting Fence 分治

    C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard in ...

  5. 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 ...

  6. Codeforces 448 C. Painting Fence

    递归.分治. . . C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input ...

  7. Painting Fence

    Painting Fence Time Limit:1000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u Sub ...

  8. 【题解】Fence(单调队列)

    [题解]Fence(单调队列) POJ - 1821 题目大意 有\(k\)个粉刷匠,每个粉刷匠一定要粉刷某个位置\(S_i\),一个粉刷匠可以粉刷至多\(l_i\)个位置(必须连续\(l_i\)互不 ...

  9. Codeforces 448C:Painting Fence 刷栅栏 超级好玩的一道题目

    C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard in ...

随机推荐

  1. Filter解决中文乱码问题

    1,FIlter中编码设置 编码设置一定要在跳转页面之前 public void doFilter(ServletRequest request, ServletResponse response, ...

  2. Jenkins强制设置语言为中文

    解决方法如下: 1.使用中文版的google浏览器,并确定把语言设置成了中文.语言配置在设置页.如下: 2.直接设置jenkins的语言.强制性. 前提:先安装插件:Locale plugin 配置如 ...

  3. JAVA Eclipse开发Android如何让超出界面的部分自动显示滚动条

    在原有布局的最外围添加一层ScrollView,注意原有布局的声明也要删了 <ScrollView xmlns:android="http://schemas.android.com/ ...

  4. base64加密PHP脚本的解码方法

    转自:http://yoursunny.com/t/2009/PHP-decode/ PHP是网站服务端最流行的编程语言之一.PHP运行环境本身是开源的,服务器不加载插件时PHP脚本也无法加密.但是, ...

  5. ListView嵌套两个EditText相关显示问题

    这里说明:本人第一次写博客,可能写的不算太好.可是这个相关类型的研究与拓展,是项目中比較难得的.所以开一篇博客来总结和思考.先让我们看看项目需求. 项目需求说明: 1.须要在点击EditText的时候 ...

  6. Jquery.ajax报parseerror Invalid JSON错误的原因和解决方法:不能解析

    (默认: 自动判断 (xml 或 html)) 请求失败时调用时间.参数有以下三个:XMLHttpRequest 对象.错误信息.(可选)捕获的错误对象.如果发生了错误,错误信息(第二个参数)除了得到 ...

  7. c# 推荐5款超实用的.NET性能分析工具

    虽然.NET框架号称永远不会发生内存泄漏,原因是引入了内存回收机制.但在实际应用中,往往我们分配了对象但没有释放指向该对象的引用,导致对象永远无法释放.最常见的情况就是给对象添加了事件处理函数,但当不 ...

  8. hdu 4862 KM算法 最小K路径覆盖的模型

    http://acm.hdu.edu.cn/showproblem.php?pid=4862 选t<=k次,t条路要经过全部的点一次而且只一次. 建图是问题: 我自己最初就把n*m 个点分别放入 ...

  9. Qt on Android:将Qt调试信息输出到logcat中

    版权全部 foruok .如需转载敬请注明出处(http://blog.csdn.net/foruok). 假设你在目标 Android 设备上执行了 Qt on Android 应用,你可能希望看到 ...

  10. 配置mysql 编码

    配置mysql 编码 [client]default-character-set=utf8mb4 default-storage-engine=INNODB [mysql]default-charac ...