【题目链接】: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. 为什么要用&lt;!DOCTYPE&gt;声明

    实例: 我们常常会看到类似这种代码: <!DOCTYPE html> <html> <head> <title>文档的标题</title> ...

  2. MERGE新特性(UPDATE WHERE,DELETE WHERE,INSERT WHERE)

    MERGE语句是Oracle9i新增的语法,用来合并UPDATE和INSERT语句.通过MERGE语句,根据一张表或子查询的连接条件对另外一张表进行查询,连接条件匹配上的进行UPDATE,无法匹配的执 ...

  3. Java中的break和continue关键字使用总结

    java中的break和continue关键字使用总结   一.作用和区别   break的作用是跳出当前循环块(for.while.do while)或程序块(switch).在循环块中的作用是跳出 ...

  4. 《Haskell趣学指南》

    <Haskell趣学指南> 基本信息 原书名:Learn You a Haskell for Great Good!: A Beginner's Guide 原出版社: No Starch ...

  5. 全负荷的 Node.js[转载]

    一个Node.JS 的进程只会运行在单个的物理核心上,就是因为这一点,在开发可扩展的服务器的时候就需要格外的注意. 因为有一系列稳定的API,加上原生扩展的开发来管理进程,所以有很多不同的方法来设计一 ...

  6. DTO的一些理解(转载)

    1.什么是DTO DTO(Data Tansfer Object)即数据传输对象.之前不明白有些框架中为什么要专门定义DTO来绑定表现层中的数据,为什么不能直接用实体模型呢,有了DTO同时还要维护DT ...

  7. 多种非接触卡 ATQA 字节说明

      原文地址 13.56 MHz RFID Software An Open Source implementation of an NFC stack, and various related ut ...

  8. Transform数据权限浅析2之利用Java完成权限设置

    一:项目背景 1.1:cognos的两种建模工具 为了更好的满足客户的需求,提升报表展现的效率,一种建模工具已经不能满足报表开发和展现的需要.Cognos除了给我们提供了一种基于关系型数据库的建模工具 ...

  9. Opencv 完美配置攻略 2014 (Win8.1 + Opencv 2.4.8 + VS 2013)

    http://my.phirobot.com/blog/2014-02-opencv_configuration_in_vs.html 2012年4月给同学写了篇傻瓜式的 VS2010+Opencv- ...

  10. 【SSH三大框架】Hibernate基础第五篇:利用Hibernate完毕简单的CRUD操作

    这里利用Hibernate操作数据库完毕简单的CRUD操作. 首先,我们须要先写一个javabean: package cn.itcast.domain; import java.util.Date; ...