博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA The Tower of Babylon
阅读量:5235 次
发布时间:2019-06-14

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

Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale have been forgotten. So now, in line with the educational nature of this contest, we will tell you the whole story:

The babylonians had n types of blocks, and an unlimited supply of blocks of each type. Each type-i block was a rectangular solid with linear dimensions tex2html_wrap_inline32 . A block could be reoriented so that any two of its three dimensions determined the dimensions of the base and the other dimension was the height. They wanted to construct the tallest tower possible by stacking blocks. The problem was that, in building a tower, one block could only be placed on top of another block as long as the two base dimensions of the upper block were both strictly smaller than the corresponding base dimensions of the lower block. This meant, for example, that blocks oriented to have equal-sized bases couldn't be stacked.

Your job is to write a program that determines the height of the tallest tower the babylonians can build with a given set of blocks.

Input and Output

The input file will contain one or more test cases. The first line of each test case contains an integer n, representing the number of different blocks in the following data set. The maximum value for n is 30. Each of the next n lines contains three integers representing the values tex2html_wrap_inline40 , tex2html_wrap_inline42 and tex2html_wrap_inline44 .

Input is terminated by a value of zero (0) for n.

For each test case, print one line containing the case number (they are numbered sequentially starting from 1) and the height of the tallest possible tower in the format "Case case: maximum height = height"

Sample Input

110 20 3026 8 105 5 571 1 12 2 23 3 34 4 45 5 56 6 67 7 7531 41 5926 53 5897 93 2384 62 6433 83 270

Sample Output

Case 1: maximum height = 40Case 2: maximum height = 21Case 3: maximum height = 28Case 4: maximum height = 342

题意:

或许你曾听过巴比伦塔的传说,现在这个故事的许多细节已经被遗忘了。现在,我们要告诉你整个故事:

巴比伦人有n种不同的积木,每种积木都是实心长方体,且数目都是无限的。第i种积木的长宽高分别为{ i , y i , z i }。积木可以被旋转,所以前面的长宽高是可以互相换的。也就是其中2个组成底部的长方形,剩下的一个为高度。巴比伦人想要尽可能的用积木来堆高塔,但是两块积木要叠在一起是有条件的:只有在第一块积木的底部2个边均小于第二块积木的底部相对的2个边时,第一块积木才可以叠在第二块积木上方。例如:底部为3x8的积木可以放在底部为4x10的积木上,但是无法放在底部为6x7的积木上。

给你一些积木的资料,你的任务是写一个程式算出可以堆出的塔最高是多少。

简单题意:

有n(n<=30)种立方体,每种都有无穷多个。要求选一些立方体摞成一根尽量高的柱子(可以自行选择那条边作为高),使得每个立方体的底面长宽分别严格小于它下方立方体的底面长宽

思路:其实题目中的每种立方体都有无限个是没大有的,因为你很容易就可以想到,每个立方体最多用三次。那么我们就可以把每个立方体分成三个高不同的立方体。如果一个立方体能放在另一个立方体上面,就在这两个立方体之间连边(有向边,底面小的向底面大的连边),这样就形成了一张有向图,最后,在图上搜索最长路作DAG上的最长路即可。

吐槽:其实这个题目仔细想想还是挺水的,但可能是我太菜的原因,竟然做了辣么久┭┮﹏┭┮

#include
#include
#include
#include
using namespace std;int n,tot,num,ans,g[40*3][40*3],f[40*3];struct nond{ int x,y,z;}v[40*3];void pre(){ for(int i=1;i<=3*n;i++) for(int j=1;j<=3*n;j++){ if(i==j) continue; if(v[i].x

 

转载于:https://www.cnblogs.com/cangT-Tlan/p/7429485.html

你可能感兴趣的文章
图的深度优先遍历
查看>>
C# 之 提高WebService性能大数据量网络传输处理
查看>>
md5sum命令详解
查看>>
[bzoj1004] [HNOI2008] Cards
查看>>
应该是实例化对象的没有对属性赋值时,自动赋值为null,但不是空指针对象引用...
查看>>
原生HttpClient详细使用示例
查看>>
几道面试题
查看>>
Factory Design Pattern
查看>>
python中贪婪与非贪婪
查看>>
guava API整理
查看>>
无锁编程笔记
查看>>
jquery mobile
查看>>
如何在vue单页应用中使用百度地图
查看>>
Springboot使用步骤
查看>>
Spring属性注入
查看>>
Springboot-配置文件
查看>>
Springboot-日志框架
查看>>
SpringBoot-thymeleaf
查看>>
P1908-逆序对
查看>>
P1192-台阶问题
查看>>