【动态规划】【滚动数组】【搜索】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 dlib 面部轮廓实时检测
1.dlib 实现动态人脸检测及面部轮廓检测 模型下载连接 : http://dlib.net/files/ # coding:utf-8 import cv2 import os import dl ...
- E题hdu 1425 sort
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1425 sort Time Limit: 6000/1000 MS (Java/Others) M ...
- 【C语言】Coursera课程《计算机程式设计》台湾大学刘邦锋——Week6 String课堂笔记
Coursera课程 <计算机程式设计>台湾大学 刘邦锋 Week6 String 6-1 Character and ASCII 字符变量的声明 char c; C语言使用一个位元组来储 ...
- linux驱动基础系列--Linux 串口、usb转串口驱动分析
前言 主要是想对Linux 串口.usb转串口驱动框架有一个整体的把控,因此会忽略某些细节,同时里面涉及到的一些驱动基础,比如字符设备驱动.平台驱动等也不进行详细说明原理.如果有任何错误地方,请指出, ...
- 大公司开源网址[www]
https://github.com/blackberry https://github.com/CallForSanity?tab=repositories https://github.com/b ...
- JSON对象与字符串之间的相互转换
<html> <head> <meta name="viewport" content="width=device-width" ...
- cacti (不可以利用yum安装cacti的配置)
我们如果用yum不可以安装cacti,我们则可以利用tar包来安装!!! //cacti的配置准备 [root@localhost ~]# yum install -y epel-release [r ...
- opencv 图像转换
#include <cv.h> #include <highgui.h> int main() { CvPoint2D32f srcTri[], dstTri[]; CvMat ...
- Spring Boot with Docker
翻译自:https://spring.io/guides/gs/spring-boot-docker/ Spring Boot with Docker 这篇教程带你一步步构建一个Docker镜像用来运 ...
- 《java并发编程实战》读书笔记11--构建自定义的同步工具,条件队列,Condition,AQS
第14章 构建自定义的同步工具 本章将介绍实现状态依赖性的各种选择,以及在使用平台提供的状态依赖机制时需要遵守的各项规则. 14.1 状态依赖性的管理 对于并发对象上依赖状态的方法,虽然有时候在前提条 ...