【codeforces 234F】Fence
【题目链接】:http://codeforces.com/problemset/problem/234/F
【题意】
你有n块板要凃油漆;
然后每块板有高度h[i];(宽度都为1)
然后每块板只能凃同一种颜色;(不同板则可以涂不同颜色);
板是按下标顺序放着的;
相邻两个板i和j之间;
相同的高度,如果都有板,且它们的颜色不同,则不好的程度+1;
然后;
你能涂a平方单位的红漆,b平方单位的绿漆;
问你把这n块板涂满的最小“不好程度”;
或输出不能涂满;
【题解】
记忆化搜索;
在记录状态的时候;
只要记录前i个板,两种颜色中的一种还剩下多少就可以了,另外一种是能够确定的(只知道一种颜色用了多少,和涂了多少个板,能够知道也即唯一确定另外一种颜色还剩多少);
所以;记搜的数组开成
f[200][4e4][2]就好;
这里的最后一维用于记录前一个涂了什么颜色;
然后根据当前这一列要涂成什么颜色;
做相应的转移就好;
(好古老,要读文件才能提交,不然显示WA)
【Number Of WA】
0
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 210;
const int A = 4e4+100;
const int oo = 0x3f3f3f3f;
int n,a,b,h[N],ans;
int f[N][A][2];
int solve(int idx,int red,int green,int pre){
if (red<0 || green <0) return oo;
if (idx>n) return 0;
int & ret = f[idx][red][pre];
if (ret!=-1) return ret;
ret = min(
solve(idx+1,red-h[idx],green,0)+(pre==0?0:min(h[idx],h[idx-1])),
solve(idx+1,red,green-h[idx],1)+(pre==1?0:min(h[idx],h[idx-1]))
);
return ret;
}
int main(){
//Open();
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
Close();//scanf,puts,printf not use
//init??????
cin >> n;
cin >> a >> b;
rep1(i,1,n){
cin >> h[i];
}
ms(f,-1);
ans = solve(1,a,b,0);
if (ans>=oo){
cout <<-1<<endl;
}
else{
cout <<ans<<endl;
}
return 0;
}
【codeforces 234F】Fence的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- switch 的穿透, 以及穿透利用
switch 穿透测试: outputs: 添加break 阻止switch穿透: outputs: 利用switch的穿透功能:
- Sping面试题分析
1.开放中主要使用Spring的什么技术? (1)IOC容器管理各层的组件 (2) 使用AOP配置声明式事务 (3)整合其他框架 2简述AOP和IOC概念 AOP : Aspect Orienten ...
- [Performance] Optimize Paint and Composite for the website
"Paint" is one of the most preference killer, it can easily cost more than 60fps, and once ...
- ORACLE 參数文件介绍
ORACLE数据库启动以后.通过select * from v$parameter这个语句能够查看到oracle数据库使用的全部參数. 对于oracle的參数文件,分为spfile 二进制文件和pfi ...
- wpf获取webbroswer的两个方法
//跳转前的地址 private void WebBrowser_BeforeNavigate2(object pDisp, ref object URL, ref object Flags, ref ...
- clipper库使用的一些心得
clipper sourceforge官网:http://sourceforge.net/projects/polyclipping/ 1. 版本号差异 之前project里面使用4.8.6,近期升级 ...
- OpenCV+海康威视摄像头的实时读取
OpenCV+海康威视摄像头的实时读取 本文由 @lonelyrains出品.转载请注明出处. 文章链接: http://blog.csdn.net/lonelyrains/article/detai ...
- Spyder调试快捷键
Ctrl+1: 注释.取消注释 Ctrl+4/5: 块注释 / 取消块注释 F12: 断点 / 取消断点 F5: 运行 Ctrl+F5: 启动调试 Ctrl+F10: 单步调试,跳过函数内部实现 ...
- EOJ 3124 单词表
题目描述 提取英文文本中的单词,重复出现的单词只取一个,把它们按照字典顺序排序,建立为一个单词表. 例如:英文文本如下: “ask not what your country can do for y ...
- How to include custom library into maven local repository?--转
原文地址:https://www.mkyong.com/maven/how-to-include-library-manully-into-maven-local-repository/ There ...