Temple Build~dp(01背包的变形)

时间:2022-09-18 10:47:14

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:

Temple Build~dp(01背包的变形)

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&lpar;HDU&rpar;&period;3466 Dividing coins &lpar; DP 01背包 无后效性的理解&rpar;

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

  5. POJ&period;3624 Charm Bracelet&lpar;DP 01背包&rpar;

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

  6. HDOJ&lpar;HDU&rpar;&period;2546 饭卡&lpar;DP 01背包&rpar;

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

  7. HDOJ&lpar;HDU&rpar;&period;2602 Bone Collector &lpar;DP 01背包)

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

  8. UVA&period;10130 SuperSale &lpar;DP 01背包&rpar;

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

  9. HDU 3033 I love sneakers&excl; 我爱运动鞋 (分组背包&plus;01背包,变形)

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

随机推荐

  1. Spark Streaming源码解读之Driver中ReceiverTracker架构设计以具体实现彻底研究

    本期内容 : ReceiverTracker的架构设计 消息循环系统 ReceiverTracker具体实现 一. ReceiverTracker的架构设计 1. ReceiverTracker可以以 ...

  2. 【NodeJS 学习笔记01】不学就老了

    前言 再不学nodeJs,我们就老了......在HTML5大浪袭来的时候,很多先辈就开始了NodeJs之旅,而那时我还在做服务器端的程序后来转成前端,和梯队的距离已经很大了,因为我会服务器端语言,还 ...

  3. 转:python webdriver API 之定位一组对象

    webdriver 可以很方便的使用 find_element 方法来定位某个特定的对象,不过有时候我们却需要定位一组对象,WebElement 接口同样提供了定位一组元素的方法 find_eleme ...

  4. php pod

    //PDO:数据访问抽象层 //dsn:数据源: //带有事务功能: $dsn = "mysql:host=localhost;dbname=mydb"; ——建立数据源 //造p ...

  5. Android开发之MediaPlayer和SurfaceView组成视频播放器

    SurfaceView 使用双缓冲技术 是个重量级的组件 只要不可见,就不会创建,可见时,才会创建 只要不可见,就会销毁 SurfaceView一旦不可见,就会被销毁,一旦可见,就会被创建,销毁时停止 ...

  6. LCS 小结

    转载链接:http://www.cnblogs.com/PJQOOO/p/3897745.html 第一步:先计算最长公共子序列的长度. 实现第一步: 设一个C[i][j]: 保存Xi与Yj的LCS的 ...

  7. ligerUI实现分页

    在公司实习看到公司框架里使用了ligerUI的grid进行分页,个人感觉挺好用的,自己摸索着实现了一遍记录下来 简单来说,liger grid 就是提交准备好的数据到指定的目标请求数据,拿到数据以后, ...

  8. 【转】Objective-C Runtime

    之前在找Runtime资料,这篇条理是相对比较清晰,对我最有启发的一篇,转载以作记录. 对于iOS小白,值得多看几遍,会有不少收获. --------------------------------- ...

  9. 安装composer时,提示 &sol;usr&sol;bin&sol;env&colon; php&colon; 没有那个文件或目录

    今晚在Ubuntu环境上安装composer后,想查看下是否安装成功,使用composer -v,结果提示:/usr/bin/env: php: 没有那个文件或目录 现说说我的解决办法: 它提示的原因 ...

  10. &lbrack;PA2014&rsqb;Budowa

    [PA2014]Budowa 题目大意: 有A和B两名候选人.共有\(n(n\le1000)\)个人参加投票.他们之间形成了一个树结构,树上的结点有两种身份:专家(叶子结点)或领导(非叶子结点).每位 ...