解题报告

给篱笆上色,要求步骤最少,篱笆怎么上色应该懂吧,。,刷子能够在横着和竖着刷,不能跳着刷,,,

假设是竖着刷,应当是篱笆的条数,横着刷的话。就是刷完最短木板的长度,再接着考虑没有刷的木板,,。

递归调用,,。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define inf 999999999999999
using namespace std;
long long n,num[5010],tt;
void dfs(long long s,long long t)
{
long long ma=0,mi=inf;
int i,j;
for(i=s; i<=t; i++)
{
if(ma<num[i])
ma=num[i];
if(mi>num[i])
mi=num[i];
}
if(mi==ma)
{
tt+=min(mi,t-s+1);
return ;
}
for(i=s; i<=t; i++)
num[i]-=mi;
tt+=min(mi,t-s);
for(i=s; i<=t; i++)
{
if(num[i]>0)
{
for(j=i; j<=t; j++)
{
if(num[j]==0||(j==t&&num[j]>0))
{
long long kk=tt;
if(j==t&&num[j]>0)
{
dfs(i,j);
if(tt-kk>(j-i+1))
tt=kk+(j-i+1);
}
else
{
dfs(i,j-1);
if(tt-kk>(j-i))
tt=kk+(j-i);
}
i=j;
break;
}
}
}
}
}
int main()
{
int i,j;
scanf("%lld",&n);
for(i=1; i<=n; i++)
scanf("%lld",&num[i]);
dfs(1,n);
printf("%lld\n",min(tt,n));
return 0;
}

Painting Fence
time limit per test

1 second

memory limit per test

512 megabytes

input

standard input

output

standard output

Bizon the Champion isn't just attentive, he also is very hardworking.

Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as n vertical planks, put in a row. Adjacent planks
have no gap between them. The planks are numbered from the left to the right starting from one, the i-th plank has the width of 1 meter
and the height of ai meters.

Bizon the Champion bought a brush in the shop, the brush's width is 1 meter. He can make vertical and horizontal strokes with the brush. During a stroke the brush's
full surface must touch the fence at all the time (see the samples for the better understanding). What minimum number of strokes should Bizon the Champion do to fully paint the fence? Note that you are allowed to paint the same area of the fence multiple times.

Input

The first line contains integer n (1 ≤ n ≤ 5000) —
the number of fence planks. The second line contains n space-separated integersa1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print a single integer — the minimum number of strokes needed to paint the whole fence.

Sample test(s)
input
5
2 2 1 2 1
output
3
input
2
2 2
output
2
input
1
5
output
1
Note

In the first sample you need to paint the fence in three strokes with the brush: the first stroke goes on height 1 horizontally along all the planks. The second stroke goes on height 2 horizontally and paints the first and second planks and the third stroke
(it can be horizontal and vertical) finishes painting the fourth plank.

In the second sample you can paint the fence with two strokes, either two horizontal or two vertical strokes.

In the third sample there is only one plank that can be painted using a single vertical stroke.


Codeforces Round #256 (Div. 2/C)/Codeforces448C_Painting Fence(分治)的更多相关文章

  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. Painting Fence (搜索 or DP)

    [题目链接]:click here~~ [题目大意]:题意:你面前有宽度为1,高度给定的连续木板,每次能够刷一横排或一竖列,问你至少须要刷几次. Sample Input Input 5 2 2 1 ...

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

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

  6. Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)

    转载请注明出处:viewmode=contents" target="_blank">http://blog.csdn.net/u012860063?viewmod ...

  7. Codeforces Round #256 (Div. 2) B. Suffix Structures(模拟)

    题目链接:http://codeforces.com/contest/448/problem/B --------------------------------------------------- ...

  8. Codeforces Round #256 (Div. 2)

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

  9. Codeforces Round #256 (Div. 2/B)/Codeforces448B_Suffix Structures(字符串处理)

    解题报告 四种情况相应以下四组数据. 给两字符串,推断第一个字符串是怎么变到第二个字符串. automaton 去掉随意字符后成功转换 array 改变随意两字符后成功转换 再者是两个都有和两个都没有 ...

随机推荐

  1. 怎样查看修改sqlserver数据库的编码格式

    原文地址:http://zhidao.baidu.com/question/107168202.html SELECT COLLATIONPROPERTY('Chinese_PRC_Stroke_CI ...

  2. uva10815 by sixleaves

    题目很简单.其实stringstream就的用法和iosteam差不多,所以学习起来是很简单的.stringstream类里面有一个string缓存,str()和str(string)成员函数.前者用 ...

  3. Ubuntu 查找命令

    Ubuntu 查找文件夹 使用find命令查找find / -name 文件夹名称 -type d找到结果中含有路径 查找命令 从根目录开始查找所有扩展名为.log的文本文件,并找出包含”ERROR” ...

  4. 区间dp-hdu-4745-Two Rabbits

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4745 题目意思: 给n个环状的数,A.B两人沿相反的方向走,每单位时间走一步,要求相同时间两人到达相 ...

  5. AJAX提交到Handler.ashx一般处理程序返回json数据 (字符串拼接方式)

    <%@ WebHandler Language="C#" Class="Handler" %> using System; using System ...

  6. POJ 3678 Katu Puzzle(2 - SAT) - from lanshui_Yang

    Description Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a ...

  7. 警惕:利用Dropbox链接散播的恶意软件

    趋势科技近期发现好几起利用热门文档代管服务Dropbox的垃圾邮件.邮件的内嵌链接会下载UPATRE恶意软件变种.UPATRE下面载恶意软件而恶名昭彰,当中包含ZBOT恶意软件.CryptoLocke ...

  8. C#运用实例.读取csv里面的词条,对每一个词条抓取百度百科相关资料,然后存取到数据库

    第一步:首先需要将csv先装换成datatable,这样我们就容易进行对datatable进行遍历: /// 将CSV文件的数据读取到DataTable中 /// CSV文件路径 /// 返回读取了C ...

  9. 实现winfrom进度条及进度信息提示,winfrom程序假死处理

    1.方法一:使用线程 功能描述:在用c#做WinFrom开发的过程中.我们经常需要用到进度条(ProgressBar)用于显示进度信息.这时候我们可能就需要用到多线程,如果不采用多线程控制进度条,窗口 ...

  10. DSOframer 无法正常加载的解决方案

    不了解 DSOframer 的朋友,可以先参考文章 DSOframer 的简单介绍和资源整理. 在使用 DSOframer 时,经常会碰到各种奇奇怪怪的问题,最常见的就是控件不能正常加载.大家可以按下 ...