显然将扩张按从大到小排序之后,只有不超过前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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 树状数组 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) E - Aquarium decoration 贪心 + 平衡树

    E - Aquarium decoration 枚举两个人都喜欢的个数,就能得到单个喜欢的个数,然后用平衡树维护前k大的和. #include<bits/stdc++.h> #define ...

  8. 【预处理】【分类讨论】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains

    分几种情况讨论: (1)仅用C或D买两个 ①买两个代价相同的(实际不同)(排个序) ②买两个代价不同的(因为买两个代价相同的情况已经考虑过了,所以此时对于同一个代价,只需要保存美丽度最高的喷泉即可)( ...

  9. 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  ...

随机推荐

  1. react-native中使用Echarts,自己使用WebView封装Echarts经验

    1.工作中遇到的问题 我们在使用react-native肯定遇到过各种奇葩的问题,比如引入Echarts时候莫名报错,但是Echarts官网明显告诉我们可以懒加载的,这是因为基本上js大部分原生的组件 ...

  2. js 数组&字符串 去重

    Array.prototype.unique1 = function() { var n = []; //一个新的临时数组 for(var i = 0; i < this.length; i++ ...

  3. 2017-2018-1 《Linux内核原理与设计》第十二周作业

    <linux内核原理与设计>第十二周作业 Sql注入基础原理介绍 分组: 和20179215袁琳完成实验 一.实验说明   SQL注入攻击通过构建特殊的输入作为参数传入Web应用程序,而这 ...

  4. python基础===字符串的制表,换行基础操作

    \n\t 制表符和换行符 >>> print("Languages:\n\tPython\n\tC\n\tJavaScript") Languages: Pyth ...

  5. xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance(xsi:schemaLocation详解)

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"中xsi的意思是 :本xml文件中要用到某些来自xsi代表的“http:/ ...

  6. Python——turtle生成图片保存

    代码示例如下: from Tkinter import * from turtle import * import turtle forward(100) ts = turtle.getscreen( ...

  7. 【Android开发日记】之基础篇(二)——Android的动画效果

          什么是动画,动画的本质是通过连续不断地显示若干图像来产生“动”起来的效果.比如说一个移动的动画,就是在一定的时间段内,以恰当的速率(起码要12帧/秒以上,才会让人产生动起来的错觉)每隔若干 ...

  8. 去掉a标签的虚线框,避免出现奇怪的选中区域

    a{blr:expression(this.onFocus=this.blur())}/*去掉a标签的虚线框,避免出现奇怪的选中区域*/

  9. 八:Zookeeper开源客户端Curator的api测试

    curator是Netflix公司开源的一套ZooKeeper客户端,Curator解决了很多ZooKeeper客户端非常底层的细节开发工作.包括连接重连,反复注册Watcher等.实现了Fluent ...

  10. Maximum Subarray——经典

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...