Codeforces D 题 Field expansion

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 a, b, h, w 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
3 3 2 4 4
2 5 4 10
output
1
input
3 3 3 3 5
2 3 5 4 2
output
0
input
5 5 1 2 3
2 2 3
output
-1
input
3 4 1 1 3
2 3 2
output
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.

本题是DP裸题,记录一维确定时,另一维的最大值,开long long,溢出的全部记为该数即可AC。

#include<bits/stdc++.h>
using namespace std;
const long long INF=2e9;
long long dp[36][100005];
long long h,w,a,b;
int n;
long long ans;
long long f[100005];
bool cmp(long long x,long long y){return x>y;}
long long JUST_DO_IT()
{
    memset(dp,-1,sizeof(dp));
    dp[0][min(a,h)]=w;
    for(int i=0;i<min(n,35);i++)
    for(int j=0;j<=a;j++)
    {
        if(dp[i][j]!=-1)
        {
            long long xx=j*f[i+1],yy=dp[i][j]*f[i+1];
            xx=min(xx,a);yy=min(yy,b);
            dp[i+1][xx]=max(dp[i+1][xx],dp[i][j]);
            dp[i+1][j]=max(dp[i+1][j],yy);
        }
    }
    for(int i=0;i<=min(n,35);i++)
    {
        if(dp[i][a]>=b)
        {
            return i;
         } 
    }
    return INF;
}
int main()
{
    //wa �㣺û�з�������dpһ�Σ��´�ע�⣡ 
    cin>>a>>b>>h>>w>>n;
    for(int i=1;i<=n;i++) cin>>f[i];
    sort(f+1,f+n+1,cmp);
    ans=JUST_DO_IT();
    swap(a,b);
    ans=min(ans,JUST_DO_IT());
    if(ans>100000) cout<<"-1"<<endl;
    else cout<<ans<<endl;
}
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值