（一）题面：

## Description

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

（二）题目大意：

（三）解题思路：

1. 静下来一看不就是求一定空间内放物体的最大体积吗，就比较容易想到背包问题。
2. 我们设dp[i]表示高度为i时候的最优解;
则有dp[i]=max(dp[i]，dp[i-r[i]]+w)，w表示高度为i-r[i]的时候可以放的方块的体积，如下图；

当我们求高度为i的正四棱台的时候，求出对应高度的宽度width，那么我们就可以求出目标区域能放的正方体的总体积w，再由dp[i-r[i]]转移过来取一个最大值即可。
3. 我们不一定可以恰好满足最高高度,高度最高的时候解也不一定最优，即dp[heigth]可能不存在，也不一定最优，故我们应该取各个高度的最优值。

（四）具体代码：
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<map>
#include<algorithm>
#define LL long long
using namespace std;
const int maxn=1e6+10;
LL down,up,heigth,ans=0,r[3];
LL dp[maxn];
LL width(LL h,LL r){return (up+(down-up)*(heigth-h)*1.0/heigth)/r;}
int main(){
freopen("in.txt","r",stdin);
while(~scanf("%lld%lld%lld%lld%lld%lld",&heigth,&down,&up,&r[0],&r[1],&r[2])){
memset(dp,-1,sizeof dp);
dp[0]=0;ans=0;
for(LL i=1;i<=heigth;i++){
for(LL j=0;j<3;j++){
if(i<r[j]||dp[i-r[j]]==-1)continue;
LL w=width(i,r[j]);
dp[i]=max(dp[i],dp[i-r[j]]+w*w*r[j]*r[j]*r[j]);
}
ans=max(ans,dp[i]);
}
printf("%lld\n",ans);
}
return 0;
}


（五）题后总结：

#### 彻底掌握 Javascript（十九）Iterator 迭代器【专家辅导】

2017年06月30日 20:59

#### 第三场-J-Temple Build

2018-04-16 10:54:55

#### sql server 2008 用户名不能登陆的问题解决方法.

2012-01-11 10:42:42

#### 2017年校招全国统一模拟笔试(第三场)编程题集合

2017-06-26 10:10:44

#### 2018年全国多校算法寒假训练营练习比赛（第三场）-H-向左走（极角排序）

2018-02-04 22:32:44

#### 2018年全国多校算法寒假训练营练习比赛(第三场)_C

2018-02-04 21:49:57

#### 2018年全国多校算法寒假训练营练习比赛（第三场）

2018-02-04 19:00:25

#### 震撼收藏：《歌声飘过30年 第三场：缤纷满园（1991年－1996年）多音乐元素交汇时期》，场场精彩！

2008-12-29 20:01:00

#### 2013HDOJ暑期多校联赛第三场解题报告

2013年07月30日 366KB 下载

#### 牛客网 2018年全国多校算法寒假训练营练习比赛（第三场） 题解

2018-02-04 18:28:30