Codeforces 448 C. Painting Fence
来源:互联网 发布:mac程序图标怎么删除 编辑:程序博客网 时间:2024/05/22 08:14
递归,分治。。。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>using namespace std;const int maxn=5500;typedef long long int LL;typedef pair<int,int> pII;LL f[maxn],n;LL solve(int l,int r){ LL mx=9999999999; vector<pII> pi; for(int i=l;i<=r;i++) mx=min(mx,f[i]); bool flag=false; int duan[2]; for(int i=l;i<=r;i++) { f[i]-=mx; if(f[i]) { if(flag==false) { flag=true; duan[0]=i; } } else if(f[i]==0) { if(flag==true) { flag=false; duan[1]=i-1; pi.push_back((make_pair(duan[0],duan[1]))); } } } if(flag==true) { flag=false; duan[1]=r; pi.push_back((make_pair(duan[0],duan[1]))); } LL digui=0; int sz=pi.size(); for(int i=0;i<sz;i++) { digui+=solve(pi[i].first,pi[i].second);; } return min((LL)(r-l+1),digui+mx);}int main(){ cin>>n; for(int i=1;i<=n;i++) cin>>f[i]; cout<<solve(1,n)<<endl; return 0;}
1 0
- Codeforces 448 C. Painting Fence
- Codeforces 448C. Painting Fence
- CodeForces 448-C. Painting Fence
- codeforces 448C Painting Fence
- CodeForces-448C Painting Fence
- Codeforces 448C Painting Fence
- codeforces 448C Painting Fence
- C. Painting Fence codeforces
- codeforces C. Painting Fence
- 【杂题】 codeforces 448C Painting Fence
- CodeForces 448C - Painting Fence(分治)
- codeforces 448C Painting Fence(分治)
- CodeForces 448C-Painting Fence-贪心
- 448C. Painting Fence
- codeforces 448C C. Painting Fence(分治+dp)
- codeforces 448C C. Painting Fence(分治+dp)
- codeforces 448C C. Painting Fence(分治+dp)
- CodeForces 448 C.Painting Fence(区间DP)
- rabbitMQ WINDOWS 安装 入门
- Android开发——点击两次手机返回键退出软件
- IOS5.0中UIControllerView新方法的使用
- career cup:3.4 tower of hanoi
- 数据恢复得很好的电话都会发生(Q977177223)
- Codeforces 448 C. Painting Fence
- Linux虚拟机 网卡设置
- jdk、Tomcat、solr的安装和配置
- 网络爬虫基本原理
- ehcache框架配置文件各参数详解
- 【Leetcode长征系列】Remove Element
- [ZOJ 2285][Vjudge 24161] Building Highways [IDA*]
- 杨绛新书
- <<编程珠玑>> 生成随机文本