【题目链接】:click here~~

【题目大意】:题意:你面前有宽度为1,高度给定的连续木板,每次能够刷一横排或一竖列,问你至少须要刷几次。

Sample Input

Input
5
2 2 1 2 1
Output
3
Input
2
2 2
Output
2
Input
1
5
Output
1

搜索:

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif #include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime> #if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif // C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector> #if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif using namespace std;
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define per(i,j,k) for(int i=(int)j;i>(int)k;--i) #define lowbit(a) a&-a
#define Max(a,b) a>b?a:b
#define Min(a,b) a>b?b:a
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL;
typedef unsigned long long LLU;
typedef double db; const int N=5*1e3+10;
LL n,m,t,ans,res,cnt,tmp; LL num[N];
char str[N];
bool vis[N]; int dir4[4][2]= {{1,0},{0,1},{-1,0},{0,-1}};
int dir8[8][2]= {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}}; LL dfs(LL left,LL right)
{
LL heng=0,temp=left;
LL Min_gun=*min_element(num+left,num+right+1);
rep(i,left,right){
num[i]-=Min_gun;
}
rep(i,left,right){
if(num[i]==0){
heng+=dfs(temp,i-1);
temp=i+1;
}
}
if(temp<=right) heng+=dfs(temp,right);
return min(heng+Min_gun,right-left+1);
}
int main()
{
while(scanf("%lld",&n)!=EOF)
{
rep(i,0,n-1){
scanf("%lld",&num[i]);
}
LL result=dfs(0,n-1);
printf("%lld\n",result);
}
return 0;
}
/*首先找到n条木条最短的木条i。
然后减去它的值。再查找1到i-1,和i+1到n的最小值,因为能够竖着刷,因此比較
刷完这段区间的横着刷和竖着刷的最小值。 终于即为答案。
5
2 2 1 2 1
5
1 2 3 2 1
5
3 2 1 2 3 3
3
5
*/

Codeforces Round #256 (Div. 2) C. Painting Fence (搜索 or DP)的更多相关文章

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

  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 Round #256 (Div. 2/C)/Codeforces448C_Painting Fence(分治)

    解题报告 给篱笆上色,要求步骤最少,篱笆怎么上色应该懂吧,.,刷子能够在横着和竖着刷,不能跳着刷,,, 假设是竖着刷,应当是篱笆的条数,横着刷的话.就是刷完最短木板的长度,再接着考虑没有刷的木板,,. ...

  5. Codeforces Round #233 (Div. 2)D. Painting The Wall 概率DP

                                                                                   D. Painting The Wall ...

  6. 贪心 Codeforces Round #173 (Div. 2) B. Painting Eggs

    题目传送门 /* 题意:给出一种方案使得abs (A - G) <= 500,否则输出-1 贪心:每次选取使他们相差最小的,然而并没有-1:) */ #include <cstdio> ...

  7. Codeforces Round #267 (Div. 2) C. George and Job(DP)补题

    Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...

  8. Codeforces Round #256 (Div. 2) 题解

    Problem A: A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standar ...

  9. Codeforces Round #256 (Div. 2)

    A - Rewards 水题,把a累加,然后向上取整(double)a/5,把b累加,然后向上取整(double)b/10,然后判断a+b是不是大于n即可 #include <iostream& ...

随机推荐

  1. JQuery与JavaScript onload的区别

    1.window.onload 不能有多个,后面的功能会覆盖前面.而jQuery(document).ready()可以存在多个. 2.window.onload 在页面所有元素(包括图片,引用文件) ...

  2. Steve Lin:如何撰写一篇优秀的SIGGRAPH论文

     英文原版 PPT下载:http://vdisk.weibo.com/s/z7VKRh2i3R4YO 一篇优秀的论文应该是这样的 广大的研究同仁介绍了这篇论文所包含的重要想法和所获得的结果 在论文中描 ...

  3. invalidate和requestLayout方法源码分析

    invalidate方法源码分析 在之前分析View的绘制流程中,最后都有调用一个叫invalidate的方法,这个方法是啥玩意?我们来看一下View类中invalidate系列方法的源码(ViewG ...

  4. jquery使用jsonp进行跨域调用

    关于JSONP的概念和为什么要使用JSONP网上已经有很多教程,这一节主要演示下在JQUERY中的ajax方法怎样通过JSONP进行远程调用 首先介绍下$.ajax的参数 type:请求方式 GET/ ...

  5. 小课堂week17 编程范式巡礼第二季 并发那些事

    编程范式巡礼第二季 并发那些事 继续上周的编程范式话题,今天想聊一下并发范式. 并发也算一种范式? 真正的并发式编程,绝不只是调用线程API或使用synchronized.lock之类的关键字那么简单 ...

  6. 使用BeyondCompare比较文件夹下的文件时,相同的文件内容,但显示为不相同

    主要原因是: 两个文件行尾标题不一致而导致的,一个是PC,一个是Unix 解决办法: 随便比较文件夹中的两个文件,点击规则,去掉比较行尾(pc/mac/unix)选项,点击确认,回到文件夹比较界面,刷 ...

  7. RS报表设计采用Total汇总过滤出错

    错误信息: DMR 子查询计划失败,并产生意外错误.: java.lang.NullPointerException 如图 原因是在RS过滤器中添加了: total([门诊人次] for [明细科室] ...

  8. jQuery框架开发一个最简单的幻灯效果

    在线演示 在这个课程中,我们将介绍如何使用jQuery来开发一个最简单的图片幻灯效果. 立刻观看互动课程:jQuery框架开发一个最简单的幻灯效果 阅读原文:jQuery框架开发一个最简单的幻灯效果

  9. openstack horizon CSS 离线 改动

    Openstack horizon 的CSS主要保存在几个文件夹中,各自是horizon/static/dashboard/scss;horizon/openstack_dashboard/stati ...

  10. Android高手进阶篇4-实现侧滑菜单框架,一分钟集成到项目中

    先来看下面的这张效果图: 上面这张效果图是百度影音的,现在在Android上很流行,最初是由facebook自己实现的,而后各大应用有跟风之势,那么这种侧滑效果是如何实现的呢? 网上现在这种侧滑菜单的 ...