【动态规划】【滚动数组】【搜索】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 ...
随机推荐
- Python面向对象学习2(面向对象的语法和特性,待更新)
上一个内容我们介绍了面向对象和面向对象场景现在我们来学习下语法和特性 1,面向对象基本语法: # -*- coding:utf-8 -*- # Author: Colin Yao class Dog( ...
- I题 hdu 1234 开门人和关门人
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1234 开门人和关门人 Time Limit: 2000/1000 MS (Java/Others) ...
- 顺序图(Sequence Diagram)
顺序图(Sequence Diagram): 是一种强调对象间消息传递次序的交互图,又称为时序图或序列图.描述了在一个用例或操作的执行过程中对象如何通过消息相互交互,说明了消息如何在对象之间被发送和接 ...
- Runas replacement tool
1. RunAsSpc Runas 无法在脚本中输入密码,可以使用RunAsSpc替代. RunAsSpc = runas + password + encryption https://robotr ...
- 一个python拖库字段的小脚本
import requests import re all_column = dict() all_db = "db_zf,dg_activity,dg_activity_log,dg_ad ...
- SQL注入之逗号拦截绕过
目前所知博主仅知的两个方法 1.通过case when then 2.join [一]case when then mysql,,,,,,, ) ) end; +----+-----------+-- ...
- monkey测试===什么是monkey测试(系列一)转
本文转自:http://www.cnblogs.com/liu-ke/p/4353926.html Monkey工具使用 一. 什么是Monkey Monkey是Android中的一个命令行工具,可以 ...
- [New learn] UIKit 框架类
NSObject NSObject is the root class of most Objective-C class hierarchies. NSDataAsset The NSDataAss ...
- Python——拼接字符串
Python中可以对字符串进行拼接: 1. 使用字符串拼接运算符: + >>> "Hello" + "World" 'HelloWorld' ...
- 使用 Visual Studio 部署 .NET Core 应用 ——.Net Core 部署到Ubuntu 16.04
.Net Core 部署到Ubuntu 16.04 中的步骤 1.安装工具 1.apache 2..Net Core(dotnet-sdk-2.0) 3.Supervisor(进程管理工具,目的是服务 ...