解题报告

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

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

递归调用,,。

#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. smb相关资料

    smb相关资料 看资料就上维基 https://en.wikipedia.org/wiki/Server_Message_Block#Implementation http://www.bing.co ...

  2. hdu 4185 Oil Skimming(二分图匹配 经典建图+匈牙利模板)

    Problem Description Thanks to a certain "green" resources company, there is a new profitab ...

  3. C#中关键字ref与out的区别【转】

    在C#中,ref与out是很特殊的两个关键字.使用它们,可以使参数按照引用来传递.总的来说,通常我们向方法中传递的是值.方法获得的是这些值的一个拷贝,然后使用这些拷贝,当方法运行完毕后,这些拷贝将被丢 ...

  4. Android UI目录

    Android UI目录 序:最近一直想进阶android应用开发,虽然对一些相关的android知识都大体熟悉,但是自己的android知识体系,经不起推敲.经不起高手的垂问.经过几个月的努力学习, ...

  5. 每日一小练——Eratosthenes 筛选法

    上得厅堂.下得厨房,写得代码.翻得围墙,欢迎来到睿不可挡的每日一小练! 题目:Eratosthenes筛选法 内容: 求质数是一个非常普遍的问题,通常不外乎用数去除.除到不尽时,给定的数就是质数.可是 ...

  6. 修改ORACLE-NLS_DATE_FORMAT时间格式的四种方式

    修改ORACLE-NLS_DATE_FORMAT时间格式的四种方式 改变ORACLE -NLS_DATE_FORMAT中时间显示格式的显示有以下方式: 1.可以在用户环境变量中指定(LINUX). 在 ...

  7. C# Winform下载文件并显示进度条

    private void btnDown_Click(object sender, EventArgs e) { DownloadFile("http://localhost:1928/We ...

  8. NHibernate各种数据库连接参数文件配置方法说明

    //NHibernate各种数据库连接参数文件配置方法说明 //配置文件Config/Hibernate.cfg.xml内容如下所示: <?xml version="1.0" ...

  9. android studio SVN的搭建

    android studio 安装 SVN:http://www.it165.net/pro/html/201404/11412.html http://jingyan.baidu.com/album ...

  10. 稀疏图(邻接链表),并查集,最短路径(Dijkstra,spfa),最小生成树(kruskal,prim)

    全部函数通过杭电 1142,1162,1198,1213等题目测试. #include<iostream> #include<vector> #include<queue ...