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

这题傻逼的我,居然一开始没有看出是一个01背包 ,
感觉这题的一个关键点就是用相似三角形求maxsize 这个限制条件
我比赛的时候根本想不到,用了其他方法处理了,出现了好多BUG
maxsize = top + (high - i) * (bottom - top) / high;
然后就是基本01背包的操作了
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
LL high, bottom, top, s[];
int main() {
while(scanf("%lld%lld%lld%lld%lld%lld", &high, &bottom, &top, &s[], &s[], &s[]) != EOF) {
LL ans = , maxsize;
vector<LL>best(high + , );
for (int i = ; i <= high ; i++) {
maxsize = top + (high - i) * (bottom - top) / high;
best[i] = ;
for (int j = ; j < ; j++ ) {
if (i < s[j]) continue;
LL temp = (maxsize / s[j]) * s[j];
best[i] = max(best[i], temp * temp * s[j] + best[i - s[j]]);
ans = max(ans, best[i]);
}
}
printf("%lld\n", ans);
}
return ;
}

Temple Build~dp(01背包的变形)的更多相关文章

  1. UVA 562 Dividing coins --01背包的变形

    01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostre ...

  2. hdu 1574 RP问题 01背包的变形

    hdu 1574 RP问题 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1574 分析:01背包的变形. RP可能为负,所以这里分两种情况处理一下就好 ...

  3. USACO Money Systems Dp 01背包

    一道经典的Dp..01背包 定义dp[i] 为需要构造的数字为i 的所有方法数 一开始的时候是这么想的 for(i = 1; i <= N; ++i){ for(j = 1; j <= V ...

  4. HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)

    HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #in ...

  5. POJ.3624 Charm Bracelet(DP 01背包)

    POJ.3624 Charm Bracelet(DP 01背包) 题意分析 裸01背包 代码总览 #include <iostream> #include <cstdio> # ...

  6. HDOJ(HDU).2546 饭卡(DP 01背包)

    HDOJ(HDU).2546 饭卡(DP 01背包) 题意分析 首先要对钱数小于5的时候特别处理,直接输出0.若钱数大于5,所有菜按价格排序,背包容量为钱数-5,对除去价格最贵的所有菜做01背包.因为 ...

  7. HDOJ(HDU).2602 Bone Collector (DP 01背包)

    HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...

  8. UVA.10130 SuperSale (DP 01背包)

    UVA.10130 SuperSale (DP 01背包) 题意分析 现在有一家人去超市购物.每个人都有所能携带的重量上限.超市中的每个商品有其相应的价值和重量,并且有规定,每人每种商品最多购买一个. ...

  9. HDU 3033 I love sneakers! 我爱运动鞋 (分组背包+01背包,变形)

    题意: 有n<=100双鞋子,分别属于一个牌子,共k<=10个牌子.现有m<=10000钱,问每个牌子至少挑1双,能获得的最大价值是多少? 思路: 分组背包的变形,变成了相反的,每组 ...

随机推荐

  1. Python中安装模块的方法

    1.*nix系统上有一个地方专门有一个地方来放置安装的Python模块 比如在Mac上,这个目录的路径为: /usr/lib/python2.7 将要安装的文件拷贝到这里即可 2.下载模块包,解压后, ...

  2. 游戏安全有多重要?——GAME-TECH游戏开发者技术沙龙

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由云+社区运营团队发布在腾讯云+社区 腾讯云GAME-TECH沙龙继3月深圳站后,将于4月13日来到北京站,与游戏厂商和游戏开发者,畅聊 ...

  3. 听翁恺老师mooc笔记(13)--类型定义和联合

    typedef 虽然我们知道使用struct这个关键字定义一个结构类型,然后可以使用该结构类型定义变量.但是每次要使用的时候都需要带着struct这个关键字,那么如何摆脱这个关键字哪?C语言提供了一个 ...

  4. 20162308 实验一《Java开发环境的熟悉》实验报告

    a 20162308 实验一<Java开发环境的熟悉>实验报告 实验内容 使用JDK编译.运行简单的Java程序. 使用IDEA 编辑.编译.运行.调试Java程序. 实验要求 没有Lin ...

  5. 敏捷冲刺每日报告二(Java-Team)

    第二天报告(10.26  周四) 团队:Java-Team 成员: 章辉宇(284) 吴政楠(286) 陈阳(PM:288) 韩华颂(142) 胡志权(143) github地址:https://gi ...

  6. Tornado 用户身份验证框架

    1.安全cookie机制 import tornado.web session_id = 1 class MainHandler(tornado.web.RequestHandler): def ge ...

  7. appcompat v21: 让 Android 5.0 前的设备支持 Material Design

    1. 十大Material Design开源项目 2. appcompat v21: 让 Android 5.0 前的设备支持 Material Design 主题 AppCompat已经支持最新的调 ...

  8. HTTP协议以及HTTP2.0/1.1/1.0区别

    HTTP协议以及HTTP2.0/1.1/1.0区别 一.简介 摘自百度百科: 超文本传输协议(HTTP,HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议.所 ...

  9. PostgreSQL 客户端乱码问题

    关于客户端和服务器端的乱码问题, POSTGRESQL字符集问题总结 总结的很详细, 特别棒. 这里让我头痛了很久的问题在于 终端 上字符编码的问题, 由于我的mbp上的 iterm2 的默认编码为 ...

  10. phpadmin增加使得项目能连接数据库

    感谢:http://jingyan.baidu.com/article/e4511cf332b9832b845eaf27.html 值得注意: 1.phpadmin的目录:D:\developsoft ...