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设计模式菜鸟系列(十七)桥接模式建模与实现
转载请注明出处:http://blog.csdn.net/lhy_ycu/article/details/40008711 桥接模式(Bridge): 把事物和其详细实现分开(抽象化与实现化解耦),使 ...
- Mysql命令和mysqldump的一些操作
mysql -h localhost -P5100 -ua -pb -e 'use xxx; SELECT * FROM `order_info` WHERE pay_time >= 14726 ...
- ASP.NET中使用TreeView显示文件
在ASP.NET中,TreeView的使用很普遍,把它利用上来 首先加入TreeView控件 <asp:TreeView ID="driverInfoView" runat= ...
- SQL Server 2005 中实现通用的异步触发器架构 (转)
在SQL Server 2005中,通过新增的Service Broker可以实现异步触发器的处理功能.本文提供一种使用Service Broker实现的通用异步触发器方法. 在本方法中,通过Serv ...
- JobControl 的实现原理
本文地址:http://www.cnblogs.com/archimedes/p/hadoop-jobcontrol.html,转载请注明源地址. 引入实例:贝叶斯分类 贝叶斯分类是一种利用概率统计知 ...
- [Python爬虫] 之七:selenium webdriver定位不到元素的五种原因及解决办法(转载)
转载:http://www.51testing.com/html/87/300987-831171.html 1.动态id定位不到元素for example: //WebElement ...
- Cognos10.2.1配置加密信息不能被加密
好奇心害死猫,可是我不是猫.这个问题已经不是第一次出现了,之前是从10.1.1到10.2.0出现的,这次是从10.2.0到10.2.1出现的,上次由于时间的问题被搁置了,这次竟然再次遇到同样的问题,已 ...
- ipv6相关
link-local和site-local address http://blog.163.com/s_u/blog/static/13308367201052411431027/ 学习IPV6的时候 ...
- css3和html5的学习
本文是此链接的源代码.http://www.imooc.com/learn/77 关于的html5的使用: transition----含义是:过渡的过程,能够对各种属性设置变化. 有5中过渡的形式: ...
- (转)android适配各种分辨率的问题
Android设备屏幕的尺寸是各式各样的,如小米是4英寸的,Xoom平板是10英寸:分辨率也千奇百怪,800×480,960×540等:Android版本的碎片化问题更是萦绕于心,不过在设计应用时可以 ...