显然将扩张按从大到小排序之后,只有不超过前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. 解决不走onActivityResult方法

    最近在开发公司项目,在使用startActivityForResult关联俩个Activity中,发现A跳转到B,B设置setResult之后,A没有执行onActivityResult,查找一下,发 ...

  2. 7.0docker镜像和仓库

    repository:镜像的仓库 registry :docker组件的仓库,docker镜像的存储服务 tag :镜像的标签 例:ubuntu:14.04  ubuntu:latest 删除镜像 d ...

  3. perl HTML::LinkExtor模块(1)

    use LWP::Simple; use HTML::LinkExtor; $html = get("http://www.baidu.com"); $link = HTML::L ...

  4. 【目录】Python自动化运维

    目录:Python自动化运维笔记 Python自动化运维 - day2 - 数据类型 Python自动化运维 - day3 - 函数part1 Python自动化运维 - day4 - 函数Part2 ...

  5. linux编程之多线程编程

    我们知道,进程在各自独立的地址空间中运行,进程之间共享数据需要用mmap或者进程间通信机制,有些情况需要在一个进程中同时执行多个控制流程,这时候线程就派上了用场,比如实现一个图形界面的下载软件,一方面 ...

  6. 使用Redirector插件解决googleapis公共库加载的问题【转】

    转自:http://www.cnblogs.com/kari/p/5860371.html 最近访问一些面向国外的网站总是会出现ajax.googleaips.com无法加载的情况.以下为加载stac ...

  7. handle_level_irq 与handle_edge_irq 的区别【转】

    转自:http://blog.csdn.net/xavierxiao/article/details/6087277 版权声明:本文为博主原创文章,未经博主允许不得转载. Linux 里, handl ...

  8. java===java基础学习(13)---this,static(静态变量和静态方法)的使用

    package dog; public class PersonAndDog { public static void main(String[] args) { Dogs da_huang = ne ...

  9. MACACA===gradle下载和安装

    gradle下载地址: http://services.gradle.org/distributions/ 或者直接点击这个: http://services.gradle.org/distribut ...

  10. EasyHook远程进程注入并hook api的实现

    EasyHook远程进程注入并hook api的实现 http://blog.csdn.net/v6543210/article/details/44276155