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 ...
随机推荐
- hdu2074java
叠筐 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- Java获取当前目录方法整理
假设项目路径是E:\Workspaces\MyProgram\FilePath 1.使用System.getProperty("user.dir"),获得项目的根路径,返回Stri ...
- VC++中 wstring和string的互相转换实现
在VC++开发中,经常会用到string和wstring,这就需要二者之间的转换,项目中封装了wstring和string相互转换的2个函数,实现如下: //将wstring转换成string std ...
- Java基础知识强化之IO流笔记33:转换流之InputStreamReader的使用
1. InputStreamReader的使用 InputStreamReader(InputStream is):用默认的编码读取数据 InputStreamReader(InputStream i ...
- Java基础知识强化之网络编程笔记03:UDP之UDP协议发送数据 和 接收数据
1. UDP协议发送数据 和 接收数据 UDP协议发送数据: • 创建发送端的Socket对象 • 创建数据,并把数据打包 • 调用Socket对象的发送方法,发送数据包 • 释放资源 UDP协议接 ...
- git 删除配置的远程地址
删除(origin 名称需根据你本地查询出来的想删除的名字, 查询命令为 git remote -v) git remote rm origin 添加(origin 名称可根据需要添加) git re ...
- angularjs ng-repeat checkbox
<div class="col-md-3" ng-repeat="user in title.UserList"> <p class=&quo ...
- CentOS7安装Cobbler
安装EPEL源 # rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 安装cobbler ...
- OpenCV 2 Computer Vision Application Programming Cookbook读书笔记
### `highgui`的常用函数: `cv::namedWindow`:一个命名窗口 `cv::imshow`:在指定窗口显示图像 `cv::waitKey`:等待按键 ### 像素级 * 在灰度 ...
- JOSN学习总结<二> JSON的格式与语法
今晚又下班早!!嘿嘿,继续JOSN的总结吧!!!!有人说这么简单还有必要写吗???我觉得“眼里过十遍不如手里过一遍”!!有错误之处请指正!!共同学习下!!!!废话不说了,进入今晚的正题: <二& ...