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 ...
随机推荐
- TCP参数设置
我们这里应用的是CentOS5.3,并内核使用的是2.6.18-128.el5PAE #1 SMP .修改部分TCP ,有的是为了提高性能与负载,但是存在降低稳定性的风险.有的则是安全方面的配置,则有 ...
- Xcode 5 安装coco2d-iphone
从http://www.cocos2d-iphone.org/download/下载并解压缩最新版本的cocos2d,默认情况下会保存在 /Users/XXX/Downloads/cocos2d-ip ...
- android之tween动画详解
android中一共提供了两种动画,其一便是tween动画,tween动画通过对view的内容进行一系列的图像变换(包括平移,缩放,旋转,改变透明度)来实现动画效果,动画效果的定义可以使用xml,也可 ...
- linux lsof nmap netstat
lsof -i :22 # 显示22端口当前运行的程序 lsof -c ssh # 显示ssh进程打开的文件 lsof -p 2120 #显示进程id2120打开的文件 nmap -sP ...
- Spring Mvc session拦截器实现
Spring Mvc拦截器实现session过期跳转到登录页面 配置拦截器 <mvc:interceptors> <mvc:interceptor> <mvc:mappi ...
- 让图片在DIV中垂直居中
window.onload=function(){ var img = document.getElementById("imgdiv"); var div = document. ...
- C#面向对象(二)
一:抽象方法 1. 在面向对象编程语言中抽象方法指一些只有方法声明,而没有具体方法体的方法.抽象方法一般存在于抽象类或接口中. 在一些父类中,某些行为不是非常明确,因此无法用代码来具体实现,但是类还必 ...
- css制作导航栏的上下三角
1)先完成一个导航条 <style type="text/css"> .nav-ul{ list-style: none; } .nav-ul li{ width: 1 ...
- [Jquery] jQuery.cookie帮助类 (转载)
/** * Cookie plugin * * Copyright (c) [url=http://sufei.cnblogs.com/]http://sufei.cnblogs.com[/url] ...
- Hadoop_Block的几种状态_DataNode
在Hadoop 2.0 中HDFS 引入了 append 和 hflush 功能之后, 需要为 数据块增加新的状态 来尽最大可能的保证数据的一致性. 参阅文档: http://files.cnblog ...