D. Field expansion
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n extensions, the i-th of them multiplies the width or the length (by Arkady's choice) by ai. Each extension can't be used more than once, the extensions can be used in any order.

Now Arkady's field has size h × w. He wants to enlarge it so that it is possible to place a rectangle of size a × b on it (along the width or along the length, with sides parallel to the field sides). Find the minimum number of extensions needed to reach Arkady's goal.

Input

The first line contains five integers abhw and n (1 ≤ a, b, h, w, n ≤ 100 000) — the sizes of the rectangle needed to be placed, the initial sizes of the field and the number of available extensions.

The second line contains n integers a1, a2, ..., an (2 ≤ ai ≤ 100 000), where ai equals the integer a side multiplies by when the i-th extension is applied.

Output

Print the minimum number of extensions needed to reach Arkady's goal. If it is not possible to place the rectangle on the field with all extensions, print -1. If the rectangle can be placed on the initial field, print 0.

Examples
input
  1. 3 3 2 4 4
    2 5 4 10
output
  1. 1
input
  1. 3 3 3 3 5
    2 3 5 4 2
output
  1. 0
input
  1. 5 5 1 2 3
    2 2 3
output
  1. -1
input
  1. 3 4 1 1 3
    2 3 2
output
  1. 3
Note

In the first example it is enough to use any of the extensions available. For example, we can enlarge h in 5 times using the second extension. Then h becomes equal 10 and it is now possible to place the rectangle on the field.

没时间看的D居然是道暴力可以过的题唉,想着后面很难就没做,确实CF这种两小时赛制的比较机灵,有人觉得A难读,分数不高就放弃A,后面的题倒是容易看出他让你做什么。这个题的意思是你有一块h*w的

地经过放大ai倍使其不小于a*b,这不是直接dfs都可以过么,有些人以为这个扩大是相加,可能是读错题啦,这种写法类似于记忆化搜索

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = 1e6 + ;
  4. int n;
  5. int tar[N];
  6. int ans = n + ;
  7. bool cmp(int a, int b)
  8. {
  9. return a > b;
  10. }
  11. void dfs(int cur_a, int cur_b, int step)
  12. {
  13. if (!cur_a && !cur_b)
  14. {
  15. ans = min(ans, step);
  16. return;
  17. }
  18. if (step == n)
  19. return;
  20. if (tar[step] == )
  21. {
  22. while (cur_a) cur_a /= , step++;
  23. while (cur_b) cur_b /= , step++;
  24. ans = min(ans, step);
  25. return;
  26. }
  27. if (cur_a) dfs(cur_a / tar[step], cur_b, step + );
  28. if (cur_b) dfs(cur_a, cur_b / tar[step], step + );
  29. }
  30. int main()
  31. {
  32. int a, b, h, w;
  33. while (~scanf("%d%d%d%d%d", &a, &b, &h, &w, &n))
  34. {
  35. ans = n + ;
  36. for (int i = ; i < n; i++)
  37. scanf("%d", tar + i);
  38. sort(tar, tar + n, cmp);
  39. dfs((a - ) / h, (b - ) / w, );
  40. dfs((a - ) / w, (b - ) / h, );
  41. ans == n + ? printf("-1\n") : printf("%d\n", ans);
  42. }
  43. return ;
  44. }

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)(A.暴力,B.优先队列,C.dp乱搞)

    A. Carrot Cakes time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...

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

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

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

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

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

  6. 【动态规划】【滚动数组】【搜索】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]]= ...

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

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

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

  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. TCP简单程序

    服务器段: package com.dcz.socket; import java.io.IOException; import java.io.OutputStream; import java.n ...

  2. 【Web应用-迁移】迁移 Web 应用到新的应用服务计划的相关限制和说明

    现象描述 当前 Web 应用所在的应用服务计划和目标应用服务计划属于同一个资源组,但是通过 Portal 点击 “更改应用服务计划”,依旧看不到目标应用服务计划. 问题分析 导致上述问题的原因是,用户 ...

  3. HDU 3033 I love sneakers! 我爱运动鞋 (分组背包+01背包,变形)

    题意: 有n<=100双鞋子,分别属于一个牌子,共k<=10个牌子.现有m<=10000钱,问每个牌子至少挑1双,能获得的最大价值是多少? 思路: 分组背包的变形,变成了相反的,每组 ...

  4. Fedora CentOS Red Hat中让vim支持语法高亮设置

    Fedora / CentOS / Red Hat这三个系统里默认的vi是没有语法高亮显示的,白色的字体看起来很不舒服. 首先用命令行cat /etc/os-release查看当前linux系统的类型 ...

  5. 添加 SSH 公钥

    生成 SSH 密钥 ssh-keygen -t rsa -C "YOUR_EMAIL@YOUREMAIL.COM" 获取 SSH 公钥信息 cat ~/.ssh/id_rsa.pu ...

  6. CF 1119F Niyaz and Small Degrees

    打VP的时候由于CXR和XRY切题太快了导致我只能去写后面的题了 然而VP的时候大概还有一小时时想出了\(O(n^2\log n)\)的暴力,然后过了二十分钟才想到删点的优化 结果细节很多当然是写不出 ...

  7. 讲课笔记3——浮动、margin失效的问题、默认样式重置

    EO:搜索引擎优化,一般在网页里面只写一个h1标签,搜索引擎可以通过该h1标签里面的内容搜索你所写的网页(a标签和img标签最好写上title属性)标准写法: .logo { text-decorat ...

  8. myna代码

    https://github.com/TalkingData/Myna/tree/master/Dataset https://github.com/TalkingData/Myna

  9. 新版raspbian系统的固定IP配置和启用root账户的ssh登录功能的方法

    1. 2016新版raspbian系统的固定IP配置: 自2016年2月份新版raspbian系统发布以后,树莓派的固定IP配置方法就与之前不一样了. 之前在raspbian系统中编辑/etc/net ...

  10. 【转】将Eclipse中的CTRL+K搬到IDEA中

    https://my.oschina.net/sprieo/blog/224838 IDEA的该功能是CTRL+F3,行为是获取当前光标位置的单词然后调用搜索.只需要按CTRL+F3一次,就可以实现C ...