【动态规划】【滚动数组】【搜索】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion
显然将扩张按从大到小排序之后,只有不超过前34个有效。
d[i][j]表示使用前i个扩张,当length为j时,所能得到的最大的width是多少。
然后用二重循环更新即可,
d[i][j*A[i]]=max(d[i][j*A[i]],d[i-1][j]);
d[i][j]=max(d[i][j],d[i-1][j]*A[i]);
当某次更新时,检验其符合了答案的条件,就输出。
显然可以用滚动数组优化到空间为线性。
注意爆int的问题。
此外,瞎几把搜+花式剪枝也能过。
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
bool cmp(const int &a,const int &b){
return a>b;
}
bool check(int hh,int ww,int aa,int bb){
return ((hh>=aa && ww>=bb) || (hh>=bb && ww>=aa));
}
int d[36][100010],a,b,h,w,n,A[100010];
int main(){
// freopen("d.in","r",stdin);
scanf("%d%d%d%d%d",&a,&b,&h,&w,&n);
if(check(h,w,a,b)){
puts("0");
return 0;
}
for(int i=1;i<=n;++i){
scanf("%d",&A[i]);
}
sort(A+1,A+n+1,cmp);
d[0][h]=w;
for(int i=1;i<=n && i<=34;++i){
for(int j=1;j<=100000;++j){
d[i][min((ll)j*(ll)A[i],100000ll)]=max(d[i][min((ll)j*(ll)A[i],100000ll)],d[i-1][j]);
if(check(min((ll)j*(ll)A[i],100000ll),d[i][min((ll)j*(ll)A[i],100000ll)],a,b)){
printf("%d\n",i);
return 0;
}
d[i][j]=max((ll)d[i][j],min((ll)d[i-1][j]*(ll)A[i],100000ll));
if(check(j,d[i][j],a,b)){
printf("%d\n",i);
return 0;
}
}
}
puts("-1");
return 0;
}
【动态规划】【滚动数组】【搜索】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion的更多相关文章
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion
D. Field expansion time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains 【树状数组维护区间最大值】
题目传送门:http://codeforces.com/contest/799/problem/C C. Fountains time limit per test 2 seconds memory ...
- 树状数组 Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains
C. Fountains time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)(A.暴力,B.优先队列,C.dp乱搞)
A. Carrot Cakes time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...
- C.Fountains(Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)+线段树+RMQ)
题目链接:http://codeforces.com/contest/799/problem/C 题目: 题意: 给你n种喷泉的价格和漂亮值,这n种喷泉题目指定用钻石或现金支付(分别用D和C表示),C ...
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) 一夜回到小学生
我从来没想过自己可以被支配的这么惨,大神讲这个场不容易掉分的啊 A. Carrot Cakes time limit per test 1 second memory limit per test 2 ...
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) E - Aquarium decoration 贪心 + 平衡树
E - Aquarium decoration 枚举两个人都喜欢的个数,就能得到单个喜欢的个数,然后用平衡树维护前k大的和. #include<bits/stdc++.h> #define ...
- 【预处理】【分类讨论】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains
分几种情况讨论: (1)仅用C或D买两个 ①买两个代价相同的(实际不同)(排个序) ②买两个代价不同的(因为买两个代价相同的情况已经考虑过了,所以此时对于同一个代价,只需要保存美丽度最高的喷泉即可)( ...
- Codeforces Round #413, rated, Div. 1 + Div. 2 C. Fountains(贪心 or 树状数组)
http://codeforces.com/contest/799/problem/C 题意: 有n做花园,有人有c个硬币,d个钻石 (2 ≤ n ≤ 100 000, 0 ≤ c, d ≤ 100 ...
随机推荐
- grunt、Browsersync服务及weinre远程调试
一.grunt server服务 前端开发时,经常需要把静态文件映射成web服务,传统的做法是丢到apache,但太重太不友好了.开发angular的时候,官方的chrome插件对file:///的支 ...
- js基础知识点收集
js基础知识点收集 js常用基本类型 function show(x) { console.log(typeof(x)); // undefined console.log(typeof(10)); ...
- python中正则用法举例
一.根据正则表达式替换字符串 import re text='abc123' text=re.sub(r'\d','-',text) print(text) 输出:abc---将每个数字替换为-,如果 ...
- 网络协议之HTTP协议
HTTP协议详解(真的很经典) 转自:http://blog.csdn.net/gueter/archive/2007/03/08/1524447.aspx Author :Jeffrey 引言 HT ...
- 2018DDCTF Misc部分WP
题目给出了这样一串字符:d4e8e1f4a0f7e1f3a0e6e1f3f4a1a0d4e8e5a0e6ece1e7a0e9f3baa0c4c4c3d4c6fbb9e1e6b3e3b9e4b3b7b7 ...
- php中的parse_ini_file函数
作用:parse_ini_file() 函数解析一个配置文件,并以数组的形式返回其中的设置 格式:parse_ini_file(file,true)// (第二个参数为可选参数.如果设置为 true, ...
- Django 1.10中文文档-第一个应用Part6-静态文件
本教程上接Part5 .前面已经建立一个网页投票应用并且测试通过,现在主要讲述如何添加样式表和图片. 除由服务器生成的HTML文件外,网页应用一般还需要提供其它必要的文件——比如图片.JavaScri ...
- JS阶段测试
JS阶段测试 一.选择题 1.表单中的数据要提交到的处理文件由表单的( c )属性指定. A. method B. name C. action D. 以上都不对 2.在CSS样式 ...
- ERROR: do not initialise statics to false
Question about git commit rule I git commit a patch, The patch has a "static int xxxxxxxxxxxxxx ...
- python基础===字符串的制表,换行基础操作
\n\t 制表符和换行符 >>> print("Languages:\n\tPython\n\tC\n\tJavaScript") Languages: Pyth ...