算法题:UVA 437 The Tower of Babylon (dp + DAG最长序列)

The Tower of Babylon

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 . 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 , and .

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

1
10 20 30
2
6 8 10
5 5 5
7
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
5
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
0

Sample Output

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

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索block
, maximum
, height
, of
The
babylon tower、dag最长路径、babylon、coat babylon系列、river of babylon,以便于您获取更多的相关知识。

时间: 2024-12-10 17:59:03

算法题:UVA 437 The Tower of Babylon (dp + DAG最长序列)的相关文章

UVa 437 The Tower of Babylon:DP&DAG

437 - The Tower of Babylon Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_problem&problem=378 思路: 对于一个(x,y,z)砖头,它可以有3中姿势放置: (前两个为地面,后一个为高) x, y, z x, z, y y, z, x 把每种姿势

算法:uva 437

题目大意 有n种长宽高为x,y,z的砖头,每种都有无数个. 砖头可以用不同姿势的方向来盖 . 砖头a以某种姿势可以盖在砖头b上,当且仅当a的底部的长宽都要比b的底部长宽要小. 问 最高可以建多高? 思路 对于一个x,y,z砖头,它可以有3中姿势放置. (前两个为地面 ,后一个为高) x, y, z x, z, y y, z, x 把每种姿势都记录下来,变成了有3*n 种固定姿势的砖头. 然后建图,g[i][j] = true, 表示砖头i可以盖在砖头j上,反之亦然. 然后就是求dag上的最长路了

算法:uva 10934 Dropping water balloons(dp | 难想)

题意 你有k个一模一样的水球,在一个n层楼的建筑物上进行测试,你想知道水球最低从几层楼往 下丢可以让水球破掉.由于你很懒,所以你想要丢最少次水球来测出水球刚好破掉的最低楼层.(在最糟情 况下,水球在顶楼也不会破)你可以在某一层楼丢下水球来测试,如果水球没破,你可以再捡起来继续用. Input 输入的每一行包含多组测试,每组测试为一行.每组测试包含两个整数 k 和 n, 1 <= k <= 100 而 n 是一个 64 位的整数(没错,这栋建筑物的确很高),最后一组k = 0,n=0 代表 结束

算法:uva 1351 String Compression(字符串区间dp)

题目大意 给一个字符串,可以把连续相同的部分进行缩写成k(S)的形式,S是一个字符串,k表示 有连续相同的S 例如,abgogogogo,可以缩写成ab4(go). 还可以嵌套缩写,比如 "nowletsgogogoletsgogogo", 缩写成"now2(lets3(go))" 思路 一道区间dp,但是这题并 不好想 f(i, j)表示字符串的i~j位的最小位数 那么 f(i, j) = min{  min{ f(i,k)+f(k+1, j), i<=k&

算法:uva 10003 Cutting Sticks (区间dp)

题目大意 一根长为l的木棍,上面有n个"切点",每个点的位置为c[i] 要按照一定顺 序把每个点都砍段,最后变成了n+1段 每砍一次,就会有一个花费,例如长度为10,"切点"为2,那么砍完 后会变成两段2,8, 那么花费为2+8=10 如果有多个"切点",那么不同顺序切会得到不同的花费. 最小 花费是多少? 思路 注意要增加一个c[n] = l f(i, j) 表示(i,j)区间的最小花费 f(i, j) = min{ f(i,k)+f(k+1,

算法题之UVA 763

Fibinary Numbers The standard interpretation of the binary number 1010 is 8 + 2 = 10. An alternate way to view the sequence ``1010'' is to use Fibonacci numbers as bases instead of powers of two. For this problem, the terms of the Fibonacci sequence

算法题:uva 10318

题目链接: 首先,可以确定每个格子只能选一次,因为选任何大于0的偶数次,等于没有效果 一样. 然后,就可以把这题理解成从r*c的矩阵中选择一些格子进行"点亮"操作,使得最终所 有格子都是"亮"的状态.那么,每个格子要么有点亮操作,要么没有,总共复杂度为2^25,显然必须 进行减枝. 假设从第一行第一列开始,从左往右,从上往下一次依次选择,对于当前所在位置( x, y),它已经不能影响到x-2以前的行数了,所以当到x行时,如果第x-2行没有全部点亮,则进行减枝 . 此

算法题:uva 1330

题目链接: http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&category=460&page=show_problem&problem=4076 以前做过一道一维的,这题只是变成了二维的,其他方法都一样.HDU 1506  Largest Rectangle in a Histogram   题解 代码1: #include<cstdio> #include<cs

一个算法题,求答案啊啊啊啊

问题描述 一个算法题,求答案啊啊啊啊 白班 09:00-18:00 通班 09:00-21:00 每个人每个月通班数量必须等于早中班和中晚班数量之和 早中班 09:00-15:00 中晚班 15:00-21:00 假设:每月按照30计算. 排班规则: 1.每个人每个月固定休息6天连续上班天数不超过7天. 2.每天各班次上班的人数最低需求:8个白班5个通班1个早中班,2个中晚班. 3.每个月每个人的通班天数安排不超过8天. 4.每个人每个月早中班和中晚班的天数之和需要与通班天数相等. 5.每月最多