Codeforces Round #256 (Div. 2/C)/Codeforces448C_Painting Fence(分治)
来源:互联网 发布:公共财政预算收入知乎 编辑:程序博客网 时间:2024/04/29 07:08
解题报告
给篱笆上色,要求步骤最少,篱笆怎么上色应该懂吧,,,刷子可以在横着和竖着刷,不能跳着刷,,,
如果是竖着刷,应当是篱笆的条数,横着刷的话,就是刷完最短木板的长度,再接着考虑没有刷的木板,,,
递归调用,,,
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#define inf 999999999999999using namespace std;long long n,num[5010],tt;void dfs(long long s,long long t){ long long ma=0,mi=inf; int i,j; for(i=s; i<=t; i++) { if(ma<num[i]) ma=num[i]; if(mi>num[i]) mi=num[i]; } if(mi==ma) { tt+=min(mi,t-s+1); return ; } for(i=s; i<=t; i++) num[i]-=mi; tt+=min(mi,t-s); for(i=s; i<=t; i++) { if(num[i]>0) { for(j=i; j<=t; j++) { if(num[j]==0||(j==t&&num[j]>0)) { long long kk=tt; if(j==t&&num[j]>0) { dfs(i,j); if(tt-kk>(j-i+1)) tt=kk+(j-i+1); } else { dfs(i,j-1); if(tt-kk>(j-i)) tt=kk+(j-i); } i=j; break; } } } }}int main(){ int i,j; scanf("%lld",&n); for(i=1; i<=n; i++) scanf("%lld",&num[i]); dfs(1,n); printf("%lld\n",min(tt,n)); return 0;}
0 0
- Codeforces Round #256 (Div. 2/C)/Codeforces448C_Painting Fence(分治)
- Codeforces Round #256 (Div. 2) C. Painting Fence(分治贪心)
- Codeforces Round #256 (Div. 2) C. Painting Fence(分治+贪心)(好题)
- Codeforces Round #256 (Div. 2) C. Painting Fence
- Codeforces Round #256 (Div. 2) C Painting Fence
- Codeforces Round #256 (Div. 2)C. Painting Fence
- Codeforces Round #256 (Div. 2) C. Painting Fence
- 递归解Codeforces Round #256 (Div. 2)C. Painting Fence
- Codeforces Round #256 (Div. 2) C. Painting Fence (DFS)
- Codeforces Round #256 (Div. 2)-C. Painting Fence
- Codeforces Round #256 (Div. 2) C (448C)Painting Fence
- Codeforces Round #256 (Div. 2) C. Painting Fence 搜索或DP
- Codeforces Round #256 (Div. 2) C. Painting Fence (搜索 or DP)
- Codeforces Round #256 (Div. 2)——Painting Fence
- cf #256 (Div. 2) C. Painting Fence 分治
- Codeforces Round #211 (Div. 2), problem: (A) Soroban,problem: (B) Fence,problem: (C)
- codeforces Round #117 Div.2 182E. Wooden Fence
- Codeforces Round #145 (Div. 2, ACM-ICPC Rules) Fence
- 打车乱象
- OS X 自动关机设置
- 人发帖胰岛素翻译素养
- 今日作息及食谱(7.19)
- AIDL介绍和实例讲解
- Codeforces Round #256 (Div. 2/C)/Codeforces448C_Painting Fence(分治)
- Linux文件基本操作管理和系统目录结构
- 基于 DPDK 的共享哈希表实现
- 装机必备知识
- HDUJ 2023 求平均成绩
- 用AsyncTask实现多线程
- 终于开博了
- POJ3264
- Android Support v4、v7、v13的区别和应用场景