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 ...
随机推荐
- Director Scene Layer and Sprite
Scenes Director Layers Multiple Layers Example: Sprites References Scenes A scene (implemented with ...
- java与javax有什么区别?
java 是java j2sdk 中的类库,也就是Java Development kit . 它提供也一些基础的东西,如io库.桌面程序的类库,如awt.集合库(如Collection.List.M ...
- Linux学习笔记总结--CentOS 设置静态IP
1.修改网卡配置 vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 #描述网卡对应的设备别名,例如ifcfg-eth0的文件中它为eth ...
- [Eclipse]The type XXX cannot be resolved. It is indirectly referenced from required .class files
在Eclipse中遇到The type XXX cannot be resolved. It is indirectly referenced from required .class files错误 ...
- python 入门1
python的历史 Python是一种解释型.面向对象.动态数据类型的高级程序设计语言. Python由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年. 像Per ...
- SQL Server 游标
结果集,结果集就是select查询之后返回的所有行数据的集合. 在关系数据库中,我们对于查询的思考是面向集合的.而游标打破了这一规则,游标使得我们思考方式变为逐行进行. 正常面向集合的思维方式是: 而 ...
- Spring Framework jar官方直接下载路径
SPRING官方网站改版后,建议都是通过 Maven和Gradle下载,对不使用Maven和Gradle开发项目的,下载就非常麻烦,下给出Spring Framework jar官方直接下载路径: h ...
- 多个互相有联系的checkbox的单选逻辑
checkbox单选的状态逻辑,状态好的时候一下就写好了,状态不好的时候要调试比较久,当然主要是对其中的事件不太清楚. 先给出效果图吧. 然后给出代码, selectZhiFuBaoPay.setOn ...
- 浅谈.net中的params关键字
先举个例子: 代码如下: class Program { static void Main(string[] args) { Console.WriteLine(Sum(1)); Console.Wr ...
- CI 笔记 数据库
demo: 1. 建立数据库,driver, 字段 name,telphone,idcard,car,content 2. 建立model,Driver_model.php文件, 建立add方法, ...