Temple Build Gym - 101656J —— 类似背包

Temple Build
The Dwarves of Middle Earth are renowned for their delving and smithy ability, but they are
also master builders. During the time of the dragons, the dwarves found that above ground the
buildings that were most resistant to attack were truncated square pyramids (a square pyramid
that does not go all the way up to a point, but instead has a flat square on top).
The dwarves knew what the ideal building shape should be based on the height they wanted
and the size of the square base at the top and bottom. They typically had three different sizes of
cubic bricks with which to work. Their goal was to maximize the volume of such a building based
on the following rules:
The building is constructed of layers; each
layer is a single square of bricks of a single size.
No part of any brick may extend out from the
ideal shape, either to the sides or at the top. The
resulting structure will have jagged sides and may
be shorter than the ideal shape, but it must fit
completely within the ideal design. The picture
at the right is a vertical cross section of one such
tower.
There is no limit on how many bricks of each
type can be used.
Input
Each line of input will contain six entries, each separated by a single space. The entries represent
the ideal temple height, the size of the square base at the bottom, the size of the square base at the
top (all three as non-negative integers less than or equal to one million), then three sizes of cubic
bricks (all three as non-negative integers less than or equal to ten thousand). Input is terminated
upon reaching end of file.
Output
For each line of input, output the maximum possible volume based on the given rules, one output
per line.
Sample Input
500000 800000 300000 6931 11315 5000
Sample Output
160293750000000000

题意:

给你一个四角的三维等腰梯形,然后有3种正方体,一层铺一种,问你最大可以放的体积是多少。

题解:

背包的思想,但是不能先for物品,一定要先for高度,再for物品,因为这个是往上的,中间不存在空隙,而背包中间允许存在空隙,注意这一点就好了,梯形在 h ′ h_{'} h高度的长可以先把梯形当做一个正方形,去掉两边,用相似三角形的方法可以把 h ′ h_{'} h的长求出来,在用底边长减去就好了。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[5],dp[1000005];
bool cmp(int a,int b)
{
    return b>a;
}
int main()
{
    ll h,base,btn;
    while(~scanf("%lld%lld%lld",&h,&base,&btn))
    {
        memset(dp,-1,sizeof(dp));
        for(int i=1;i<=3;i++)
            scanf("%lld",&a[i]);
        sort(a+1,a+4,cmp);
        dp[0]=0;
        for(int i=1;i<=3;i++)
        {
            for(ll j=a[i];j<=h;j++)
            {
                if(dp[j-a[i]]==-1)
                    continue;
                ll num=(ll)((base-1.0*j/h*(base-btn))/a[i]+1e-6);
                dp[j]=max(dp[j],dp[j-a[i]]+num*num*a[i]*a[i]*a[i]);
            }

        }
        ll ans=0;
        for(int i=0;i<=h;i++)
            ans=max(ans,dp[i]);
        printf("%lld\n",ans);
    }
    return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值