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 ...
随机推荐
- linux 提高进程优先级nice+ 进程调度CFS
http://www.cnblogs.com/wang_yb/archive/2012/09/04/2670564.htmlhttp://liwei.life/2016/04/07/linux%E7% ...
- 使用 JSSE 定制 SSL 连接的属性--转载
当数据在网络上传播的时候,通过使用 SSL 对其进行加密和保护,JSSE 为 Java 应用程序提供了安全的通信.在本篇有关该技术的高级研究中,Java 中间件开发人员 Ian Parkinson 深 ...
- 鸟哥的Linux私房菜学习笔记(1)
2014/10/29 1.档案的权限管理分为三个部分: 拥有者.群组.其他 2.ls -al 命令可以看到档案的详细信息 3.档案的属性中由十个部分构成 第一个部分是档案类型 -代表档案.d代表文件夹 ...
- CentOS 6.7平台Hadoop 1.2.1环境搭建
本教程使用Vultr的VPS搭建,主要实现HDFS和MapReduce两个功能. master.hadoop - 45.32.90.100 slave1.hadoop - 45.32.92.47 sl ...
- spring计划任务,springMvc计划任务,Spring@Scheduled,spring定时任务
spring计划任务,springMvc计划任务,Spring@Scheduled,spring定时任务 >>>>>>>>>>>> ...
- 程序员带你学习安卓开发,十天快速入-对比C#学习java语法
关注今日头条-做全栈攻城狮,学代码也要读书,爱全栈,更爱生活.提供程序员技术及生活指导干货. 如果你真想学习,请评论学过的每篇文章,记录学习的痕迹. 请把所有教程文章中所提及的代码,最少敲写三遍,达到 ...
- Memcache简介
简介 Memcache是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的hash表,它能够用来存储各种格式的数据,包括图像.视频.文件以及数据库检索的结果等.简单的说就是将数据调 ...
- CI框架篇之类库篇--基础(1)
使用 CodeIgniter 类库: 所有的类库文件存放在system/libraries 文件夹.大多数情况下你需要预先在controller中初始化后才能使用它们: $this->load- ...
- 在C#中使用正则表达式自动匹配并获取所需要的数据
转自:http://my.oschina.net/bv10000/blog/111736 正则表达式能根据设置匹配各种数据(比如:e-mail地址,电话号码,身份中号码等等).正则表达式功能强大,使用 ...
- VMWare ESX Server
VMWare ESX Server 4.1 全套下载 [转自:http://www.awolf.net/content/hack/vmware-esx-server-4-1-all-download. ...