Temple Build~dp(01背包的变形)
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背包的变形)的更多相关文章
- UVA 562 Dividing coins --01背包的变形
01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostre ...
- hdu 1574 RP问题 01背包的变形
hdu 1574 RP问题 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1574 分析:01背包的变形. RP可能为负,所以这里分两种情况处理一下就好 ...
- USACO Money Systems Dp 01背包
一道经典的Dp..01背包 定义dp[i] 为需要构造的数字为i 的所有方法数 一开始的时候是这么想的 for(i = 1; i <= N; ++i){ for(j = 1; j <= V ...
- HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)
HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #in ...
- POJ.3624 Charm Bracelet(DP 01背包)
POJ.3624 Charm Bracelet(DP 01背包) 题意分析 裸01背包 代码总览 #include <iostream> #include <cstdio> # ...
- HDOJ(HDU).2546 饭卡(DP 01背包)
HDOJ(HDU).2546 饭卡(DP 01背包) 题意分析 首先要对钱数小于5的时候特别处理,直接输出0.若钱数大于5,所有菜按价格排序,背包容量为钱数-5,对除去价格最贵的所有菜做01背包.因为 ...
- HDOJ(HDU).2602 Bone Collector (DP 01背包)
HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...
- UVA.10130 SuperSale (DP 01背包)
UVA.10130 SuperSale (DP 01背包) 题意分析 现在有一家人去超市购物.每个人都有所能携带的重量上限.超市中的每个商品有其相应的价值和重量,并且有规定,每人每种商品最多购买一个. ...
- HDU 3033 I love sneakers! 我爱运动鞋 (分组背包+01背包,变形)
题意: 有n<=100双鞋子,分别属于一个牌子,共k<=10个牌子.现有m<=10000钱,问每个牌子至少挑1双,能获得的最大价值是多少? 思路: 分组背包的变形,变成了相反的,每组 ...
随机推荐
- WEB端线上偶现问题如何复现?
1.抓取出现问题的日志,还原操作过程,分析 每个过程中数据是否正常?是否有重复请求 2.询问当时操作员执行了哪些操作,尽可能多的了解事发经过 3.通过查看日志,数据库等信息,找到发生问题的节点, 比如 ...
- vmware虚拟机和网络中的桥接和NAT
vmware虚拟机和网络中的桥接和NAT 有许多人在网上回答类似的问题,但大多说的不够简单,且互相抄袭的嫌疑很大,这里我尽自己努力把问题说的明白一些 首先解释一下什么是NAT(network addr ...
- C# Unity游戏开发——Excel中的数据是如何到游戏中的 (四)2018.4.3更新
本帖是延续的:C# Unity游戏开发--Excel中的数据是如何到游戏中的 (三) 最近项目不算太忙,终于有时间更新博客了.关于数据处理这个主题前面的(一)(二)(三)基本上算是一个完整的静态数据处 ...
- vue 在methods中调用mounted中的方法?
首先可以在data中先声明一个变量 比如 isShow=' ' mounted 中 ---> methods 中 ---> this.sureDelBox(item) 直接this调用 ...
- installutil 安装windows service
1:路径:C:\Windows\Microsoft.NET\Framework\v4.0.30319 2:执行指令:C:\Windows\Microsoft.NET\Framework\v4.0.30 ...
- kali linux 2.0 web 渗透测试 电子书
原创 2017-05-31 玄魂工作室 玄魂工作室 打起精神,重新开启订阅号的原创文章写作工作,但是需要点时间,请耐心等待. 求资料的同学,没有及时回复的,请再次留言,我会尽快处理.今天分享两本电子书 ...
- Linq 延迟加载
IList<Student> ssList = new List<Student>() { , StudentName = "John", } , , St ...
- [UWP]针对UWP程序多语言支持的总结,含RTL
UWP 对 Globalization and localization 的支持非常好,可以非常容易地实现应用程序本地化. 所谓本地化,表现最为直观的就是UI上文字和布局方式了,针对文字,提供不同的语 ...
- redis入门(03)redis的配置
一.配置文件 Redis 的配置文件位于 Redis 安装目录下,文件名为 redis.conf.你可以通过 CONFIG 命令查看或设置配置项. 二.查看修改 1.查看配置 1.1.vi redis ...
- 单点登录实现机制:web-sso
参考链接,感谢作者:https://zm10.sm-tc.cn/?src=l4uLj8XQ0IiIiNGckZ2TkJiM0ZyQktCZlo2Mi5uNmp6S0I/QysrJyszPztGXi5K ...