博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Temple Build~dp(01背包的变形)
阅读量:5244 次
发布时间:2019-06-14

本文共 2784 字,大约阅读时间需要 9 分钟。

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背包的操作了
1 #include 
2 #include
3 #include
4 #include
5 #include
6 using namespace std; 7 typedef long long LL; 8 LL high, bottom, top, s[3]; 9 int main() {10 while(scanf("%lld%lld%lld%lld%lld%lld", &high, &bottom, &top, &s[0], &s[1], &s[2]) != EOF) {11 LL ans = 0, maxsize;12 vector
best(high + 1, 0);13 for (int i = 0 ; i <= high ; i++) {14 maxsize = top + (high - i) * (bottom - top) / high;15 best[i] = 0;16 for (int j = 0 ; j < 3 ; j++ ) {17 if (i < s[j]) continue;18 LL temp = (maxsize / s[j]) * s[j];19 best[i] = max(best[i], temp * temp * s[j] + best[i - s[j]]);20 ans = max(ans, best[i]);21 }22 }23 printf("%lld\n", ans);24 }25 return 0;26 }

 

转载于:https://www.cnblogs.com/qldabiaoge/p/8877891.html

你可能感兴趣的文章
20162304 2017-2018-1 《程序设计与数据结构》第二周学习总结
查看>>
九.python面向对象(双下方法内置方法)
查看>>
2018-09-12
查看>>
go:channel(未完)
查看>>
[JS]递归对象或数组
查看>>
CSS与Theme的作用——Asp.Net
查看>>
LeetCode(17) - Letter Combinations of a Phone Number
查看>>
20165115 2017-2018-2 《Java程序设计》第四周学习总结
查看>>
Linux查找命令对比(find、locate、whereis、which、type、grep)
查看>>
WPF自定义集合控件概述与遇到的问题
查看>>
路由器外接硬盘做nas可行吗?
查看>>
python:从迭代器,到生成器,再到协程的示例代码
查看>>
pytest的参数化测试
查看>>
Java多线程系列——原子类的实现(CAS算法)
查看>>
安装Pygame和pip的艰辛之路
查看>>
Hibernate的实体类为什么需要实现 java.io.Serializable 接口
查看>>
在Ubuntu下配置Apache多域名服务器
查看>>
多线程《三》进程与线程的区别
查看>>
Min Stack
查看>>
老鸟的Python入门教程
查看>>