略有上升称号,最近有很多问题,弥补啊,各类竞赛滥用,来不及做出了所有的冠军。这个话题 这是一个长期记忆的主题。这是不是太困难,基本技能更灵活的测试,每次我们来看看这个问题可以被删除,处理然后分段层,贪婪的想法画一幅画,可以发现,下一步骤是如何应用,搜递归就能够了。当时写错了。还是漏了一些,如今补题才发现,长记性咯

http://codeforces.com/contest/448/problem/C

#include<iostream>
#include<cstdio>
#include<list>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<cmath>
#include<memory.h>
#include<set> #define ll long long #define eps 1e-8 const int inf = 0xfffffff; const ll INF = 1ll<<61; using namespace std; //vector<pair<int,int> > G;
//typedef pair<int,int > P;
//vector<pair<int,int> > ::iterator iter;
//
//map<ll,int >mp;
//map<ll,int >::iterator p; int dfs(vector<int > G) {
int minn = inf;
int len = G.size();
for(int i=0;i<G.size();i++)
minn = min(G[i],minn);
if(minn > len)return len;//这样横着来不如竖着来
for(int i=0;i<G.size();i++)
G[i] -= minn;
int ans = minn;
vector<int > now;
for(int i=0;i<G.size();i++) {
if(G[i])
now.push_back(G[i]);
else {
ans += dfs(now);
now.clear();
}
}
if(now.size())
ans += dfs(now);
ans = min(len,ans);
return ans;
} int main() {
int n;
while(scanf("%d",&n) == 1) {
vector<int > G;
for(int i=0;i<n;i++) {
int x;
scanf("%d",&x);
G.push_back(x);
}
int ans = dfs(G);
printf("%d\n",ans);
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

Code Forces 448C Painting Fence 贪婪的递归的更多相关文章

  1. CF448C Painting Fence (分治递归)

    Codeforces Round #256 (Div. 2) C C. Painting Fence time limit per test 1 second memory limit per tes ...

  2. [Codeforces 448C]Painting Fence

    Description Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion ...

  3. cf 448c Painting Fence

    http://codeforces.com/problemset/problem/448/C 题目大意:给你一个栅栏,每次选一横排或竖排染色,求把全部染色的最少次数,一个点不能重复染色. 和这道题有点 ...

  4. Codeforces 448C Painting Fence:分治

    题目链接:http://codeforces.com/problemset/problem/448/C 题意: 有n个木板竖着插成一排栅栏,第i块木板高度为a[i]. 你现在要将栅栏上所有地方刷上油漆 ...

  5. 448C - Painting Fence(分治)

    题意:给出宽为1高为Ai的木板n条,排成一排,每次上色只能是连续的横或竖并且宽度为1,问最少刷多少次可以使这些木板都上上色 分析:刷的第一步要么是所有的都竖着涂完,要么是先横着把最矮的涂完,如果是第一 ...

  6. Codeforces 448C Painting Fence(分治法)

    题目链接:http://codeforces.com/contest/448/problem/C 题目大意:n个1* a [ i ] 的木板,把他们立起来,变成每个木板宽为1长为 a [ i ] 的栅 ...

  7. Codeforces 448C:Painting Fence 刷栅栏 超级好玩的一道题目

    C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard in ...

  8. Codeforces 448 C. Painting Fence

    递归.分治. . . C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input ...

  9. Painting Fence

    Painting Fence Time Limit:1000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u Sub ...

随机推荐

  1. leetcode -day19 Convert Sorted List to Binary Search Tree

    1.  Convert Sorted List to Binary Search Tree Given a singly linked list where elements are sorted ...

  2. windows之实现3D立体效果的三种方法

    第一种:快捷键:win+tab 另外一种:cmd输入rundll32.exe dwmapi #105 第三种:使用软件bumptop

  3. Hibernate常用Annotation标签说明

    @ javax.persistence.Entity 实体类定义,该标签表示当前类是一个Hibernate的数据库实体,对应着数据库中的某个表 位置:用于类级别 参数:无 样例:@Entity 注意: ...

  4. 计算机本科/硕士找offer的总结 节选

    在这样的目标定位下,我的求职历程从2006年10月8日开始,到2007年1月10日正式结束,一共持续了3个月的时间.整个过程可以分为三个阶段:第一阶段:2006年10月份 找工作刚刚开始的阶段,什么都 ...

  5. Apache James使用的方法及相关心得(转)

    经过一番的辛苦努力,终于把James 配置搞定啦,好记性不如烂笔头啊,赶紧记下我的成功经过,以备以后查阅! 首先要做的就是配置域名的MX 记录啦: 先添加一条A记录: mail.abc.com 指向 ...

  6. 从零开始学Xamarin.Forms(四) Android 准备步骤(添加第三方Xamarin.Forms.Labs库)

    原文:从零开始学Xamarin.Forms(四) Android 准备步骤(添加第三方Xamarin.Forms.Labs库)  1.安装对应dll     Update-Package Xama ...

  7. 为应用程序池“XX”提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误

    场景 WCF应用程序部署在IIS7中,使用net.tcp协议对外给几百台客户端提供服务,应用程序池不断崩溃重启. 分析过程 在事件查看器中看到的错误信息类似于 为应用程序池“XX”提供服务的进程在与 ...

  8. 4pdf

    http://www.cnblogs.com/haocool/archive/2013/03/16/2962547.html

  9. APK ubuntu下 数字签名

    Android系统要求每个Android应用程序必需要经过数字签名才可以安装到系统中,也就是说假设一个Android应用程序没有经过数字签名,是没有办法安装到系统中的! Android通过数字签名来标 ...

  10. 玩转html5(一)-----盘点html5新增的那些酷酷的input类型和属性

    今天正式开始学习html5了,相比html以前的版本,html5新增了好多功能,属性,使我们做出来的界面更加的绚丽,而且使用起来超级简单,这篇文章先来说说html增加的那些input类型和属性. 这些 ...