Codeforces Round #256 (Div. 2) C. Painting Fence (搜索 or DP)
【题目链接】:click here~~
【题目大意】:题意:你面前有宽度为1,高度给定的连续木板,每次能够刷一横排或一竖列,问你至少须要刷几次。
Sample Input
5
2 2 1 2 1
3
2
2 2
2
1
5
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)的更多相关文章
- 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 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 Round #256 (Div. 2/C)/Codeforces448C_Painting Fence(分治)
解题报告 给篱笆上色,要求步骤最少,篱笆怎么上色应该懂吧,.,刷子能够在横着和竖着刷,不能跳着刷,,, 假设是竖着刷,应当是篱笆的条数,横着刷的话.就是刷完最短木板的长度,再接着考虑没有刷的木板,,. ...
- Codeforces Round #233 (Div. 2)D. Painting The Wall 概率DP
D. Painting The Wall ...
- 贪心 Codeforces Round #173 (Div. 2) B. Painting Eggs
题目传送门 /* 题意:给出一种方案使得abs (A - G) <= 500,否则输出-1 贪心:每次选取使他们相差最小的,然而并没有-1:) */ #include <cstdio> ...
- 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 ...
- Codeforces Round #256 (Div. 2) 题解
Problem A: A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #256 (Div. 2)
A - Rewards 水题,把a累加,然后向上取整(double)a/5,把b累加,然后向上取整(double)b/10,然后判断a+b是不是大于n即可 #include <iostream& ...
随机推荐
- Java隐藏手机号中间四位,隐藏身份证中间数字
原文:https://blog.csdn.net/yuanquanl/article/details/53519577 public static void main(String[] args) { ...
- There is no Action mapped for namespace [/] and action name [Login] associated with context path [/e
近期学习web开发时,就遇到这个令人头疼的问题. 百度谷歌了N遍,最终在博客http://blog.csdn.net/liu578182160/article/details/17266879中找到了 ...
- 《Android传感器高级编程》
<Android传感器高级编程> 基本信息 原书名:Professional Android Sensor Programming 原出版社: Wrox 作者: (美)米内特(Greg M ...
- Latex作者单位的写法—AND 首页脚注
IEEE会议的模板 以四个作者为例 正常: 作者单位如果名字较短,可以直接写在作者对应的下面,邮箱可以对应写在再接下来的下面. 一 如果邮箱较长,可以用\thanks{ }命令将其变为脚注.例如: ~ ...
- iOS: sqlite数据库的基本操作
介绍: sqlite3(3是版本)是本地系统中的一个小型数据库,因为它没有在数据维护和安全上做过多的操作,所以它存储处理数据时,非常简单方便,但是它是不安全和不可靠的,如果一旦误操作删除了数据,是没有 ...
- 关于一道面试题,使用C#实现字符串反转算法
关于一道面试题,使用C#实现字符串反转算法. 题目见http://student.csdn.net/space.php?do=question&ac=detail&qid=490 详细 ...
- 数据库 DB MySQL 基本操作 CRUD 多表 MD
操作数据库 创建数据库:create 创建一个名称为mydb1的数据库 create database mydb1; 创建一个使用gbk字符集的mydb2数据库 create database myd ...
- JavaScript hash
location.hash -- 返回URL#后面的内容,如果没有#,返回空 hash,中文"哈希" 引用网址:http://www.dreamdu.com/javascript/ ...
- mac远程桌面Microsoft Remote Desktop for Mac的安装与使用
mac远程桌面Microsoft Remote Desktop for Mac的安装与使用 学习了:https://blog.csdn.net/ytangdigl/article/details/78 ...
- [ES6] 02. Traceur compiler and Grunt
Local Install: npm install -g traceur npm install grunt-contrib-watch npm install grunt-traceur-lat ...