codeforces C. Painting Fence
http://codeforces.com/contest/448/problem/C
题意:给你n宽度为1,高度为ai的木板,然后用刷子刷颜色,可以横着刷、刷着刷,问最少刷多少次可以全部刷上颜色。
思路:dp[i][j] 表示在第i列以后的木板都已刷完且第j列的木板是横着刷的,最少需要的次数。如果a[i]>=a[j]的情况,比较再竖着刷一次和横着刷哪一个情况次数少。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define maxn 1000100
#define ll long long
using namespace std;
const int inf=<<; int n;
ll a[maxn];
ll dp[][]; int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
cin>>a[i];
}
a[]=;
for(int i=; i<=n; i++)
{
dp[n][i]=;
}
for(int i=n; i>=; i--)
{
for(int j=; j<=n; j++)
{
if(a[j]>=a[i])
{
dp[i-][j]=dp[i][i];
}
else dp[i-][j]=min(dp[i][j]+,dp[i][i]+a[i]-a[j]);
}
}
cout<<dp[][]<<endl;
return ;
}
codeforces C. Painting Fence的更多相关文章
- [Codeforces 448C]Painting Fence
Description Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion ...
- Codeforces 448C Painting Fence(分治法)
题目链接:http://codeforces.com/contest/448/problem/C 题目大意:n个1* a [ i ] 的木板,把他们立起来,变成每个木板宽为1长为 a [ i ] 的栅 ...
- Codeforces 448C Painting Fence:分治
题目链接:http://codeforces.com/problemset/problem/448/C 题意: 有n个木板竖着插成一排栅栏,第i块木板高度为a[i]. 你现在要将栅栏上所有地方刷上油漆 ...
- 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 256 div2 C. Painting Fence 分治
C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard in ...
- Codeforces 448 C. Painting Fence
递归.分治. . . C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input ...
- Codeforces 448C:Painting Fence 刷栅栏 超级好玩的一道题目
C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard in ...
随机推荐
- hadoop错误org.apache.hadoop.yarn.exceptions.YarnException Unauthorized request to start container
错误: 14/04/29 02:45:07 INFO mapreduce.Job: Job job_1398704073313_0021 failed with state FAILED due to ...
- Google Map API v2 步步为营 (二)----- Location
接上篇. 改造一下MapsActivity: public class MapsActivity extends Activity implements LocationListener, InfoW ...
- linux tar 压缩解压缩
解压 .tar.bz tar zxvf file.tar.gz .tar.gz2 tar jxvf file.tar.bz2 .bz gzip -d file.bz .gz2 bzip2 -d fil ...
- CentOS 6.7配置Nginx 1.8负载均衡
本教程使用Vultr的VPS搭建,准备三台VPS,一主两从 master - 45.32.90.100 slave1 - 45.32.92.47 slave2 - 45.32.89.205 1.编译安 ...
- HTML5的你应该记住的一些知识点
刚开始学HTML5是从w3school开始的,那只是非常简单的一些了解,后面开始看一些xiongdilian的HTML5+CSS3的视频,照着视频做了一些简单的demo(需要的童鞋可以联系我,当然网上 ...
- JS1-属性操作
属性操作语法 读操作:获取.找到 元素.属性名 写操作:“添加”.替换.修改 元素.属性名 = 新的值 元素.innerHTML => 读取元素里面所有的html代码 元素.innerHTML ...
- PHP in_array不兼容问题
做过日本的手机端,就因为in_array这个方法在我的环境下没有问题 结果到日本那边就是出问题,一直纠结的我啊,现在特贴出当初的兼容方法 function in_into($key,$array){ ...
- 导出excel的简单方法
excel的操作,最常用的就是导出和导入,废话不多说上代码. 本例使用NPOI实现的,不喜勿喷哈.... /// <summary> /// 导出Excel /// </summar ...
- oracle学习笔记2:创建修改表
1.创建表 CREATE TABLE ORDERINFO ( ORDERID NUMBER(*, 0) NOT NULL , ORDERCODE VARCHAR2(20 BYTE) NOT NULL ...
- struts通过Ajax返回数据时,例如对象类型,没有执行Ajax的回调函数
<result type="json" name="success"> <param name=" ...