提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 题目
  • 一、原文
  • 二、译文
  • 总结

题目

一、原文

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 (xi
, yi, zi). 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

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 xi
, yi and zi

.

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

Output

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

二、译文

你可能已经听说过巴比伦塔的传说。现在这个传说的许多细节已经被遗忘。所以本着本场比赛的教育性质,我们现在会告诉你整个传说:

巴比伦人有n种长方形方块,每种有无限个,第i种方块的三边边长是xi,yi,zi。对于每一个方块,你可以任意选择一面作为底,这样高就随着确定了。举个例子,同一种方块,可能其中一个是竖着放的,一个是侧着放的,一个是横着放的。

他们想要用堆方块的方式建尽可能高的塔。问题是,只有一个方块的底的两条边严格小于另一个方块的底的两条边,这个方块才能堆在另一个上面。这意味着,一个方块甚至不能堆在一个底的尺寸与它一样的方块的上面。

你的任务是编写一个程序,计算出这个塔可以建出的最高的高度。

【输入】

输入会包含至少一组数据,每组数据的第一行是一个整数n(n<=30),表示方块的种类数。 这组数据接下来的n行,每行有三个整数,表示xi,yi,zi。 输入数据会以0结束。

【输出】

对于每组数据,输出一行,其中包含组号(从1开始)和塔最高的高度。按以下格式: Case : maximum height = __

【输入样例】

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

【输出样例】

Case 1: maximum height = 40

Case 2: maximum height = 21

Case 3: maximum height = 28

Case 4: maximum height = 342

输入输出样例
输入 #1复制
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
输出 #1复制
Case 1: maximum height = 40
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342


总结

那么代码就放到下面了

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
struct P {int w, d, h;
} p[200];
int a[5];
int n;
bool cmp(P a, P b) {if (a.w == b.w) {return a.d < b.d;}return a.w < b.w;
}
int f[200], ans = -1;
int main() {while (cin >> n && n) {ans = -1;memset(f, 0, sizeof(f));for (int i = 1; i <= n; i++) {cin >> a[0] >> a[1] >> a[2];p[i].w = a[0], p[i].d = a[1], p[i].h = a[2];p[i + n].w = a[0], p[i + n].d = a[2], p[i + n].h = a[1];p[i + n * 2].w = a[1], p[i + 2 * n].d = a[0], p[i + 2 * n].h = a[2];p[i + 3 * n].w = a[1], p[i + 3 * n].d = a[2], p[i + 3 * n].h = a[0];p[i + 4 * n].w = a[2], p[i + 4 * n].d = a[0], p[i + 4 * n].h = a[1];p[i + 5 * n].w = a[2], p[i + 5 * n].d = a[1], p[i + 5 * n].h = a[0];}sort(p + 1, p + 6 * n + 1, cmp);for (int i = 1; i <= 6 * n; i++) {f[i] = p[i].h;for (int j = 1; j < i; j++) {if (p[i].w > p[j].w && p[i].d > p[j].d) {f[i] = max(f[j] + p[i].h, f[i]);}}ans = max(f[i], ans);}cout << ans << endl;}return 0;
}

【洛谷】UVA437 巴比伦塔 The Tower of Babylon相关推荐

  1. UVA437 巴比伦塔 The Tower of Babylon(矩形嵌套进阶版、DAG上DP、记忆化搜索)

    整理的算法模板合集: ACM模板 本题和基础的矩形覆盖差不多,只不过变成了三维的长方形. 因为每次转移的时候只有顶面的x和y会影响决策的进行,所以我们只需要用一个二元组(a,b)(a, b)(a,b) ...

  2. 题解系列009 | 洛谷题解 CF488A 【Giga Tower】

    原题传送门:Giga Tower 一.题意 题目(传送门)给一个绝对值不超过十位的整数,想计算至多加几后会在和数中出现数字 888. 二.分析 看到这道题,我们最容易想到的当然是暴力枚举,但是首先需要 ...

  3. 洛谷-题解 P2672 【推销员】

    独门思路!链表加优先队列! 这题一望,贪心是跑不掉了,但是我贪心并不好,所以想到了一个复杂一些但思路更保稳的做法 思路: 1 因为是离线操作,所以我们可以倒着求,先求x=n的情况,因为那样直接就知道了 ...

  4. 洛谷 P1142 轰炸

    洛谷 P1142 轰炸 题目描述 "我该怎么办?"飞行员klux向你求助. 事实上,klux面对的是一个很简单的问题,但是他实在太菜了. klux要想轰炸某个区域内的一些地方,它们 ...

  5. 洛谷 P1387 最大正方形

    P1387 最大正方形 题目描述 在一个n*m的只包含0和1的矩阵里找出一个不包含0的最大正方形,输出边长. 输入输出格式 输入格式: 输入文件第一行为两个整数n,m(1<=n,m<=10 ...

  6. 洛谷P2763 试题库问题

    题目:https://www.luogu.org/problemnew/show/P2763 题目描述 «问题描述: 假设一个试题库中有n道试题.每道试题都标明了所属类别.同一道题可能有多个类别属性. ...

  7. 动态规划——洛谷_P1057传球游戏

    题目: 题目描述 上体育课的时候,小蛮的老师经常带着同学们一起做游戏.这次,老师带着同学们一起做传球游戏.游戏规则是这样的:n个同学站成一个圆圈,其中的一个同学手里拿着一个球,当老师吹哨子时开始传球, ...

  8. 洛谷P1417 烹调方案

    洛谷P1417 烹调方案 如果是一般的01背包的话 选的先后是没关系的 但是这题选的先后是有关系的,因为他的价值是随着时间而变化的, 而你的01背包是做不到先选2再选1的 那么我们就跟国王游戏一样 用 ...

  9. 记忆优化搜索(简单题)(洛谷P3183 [HAOI2016]食物链 )( P5635 【CSGRound1】天下第一 )

    昨天做了蓝桥杯的时候,发现自己对于记忆优化搜索甚是不熟悉,所以今天随便找了几个基础题做做,顺便写下两片题解,顺便用了一下devc++敲的代码,发现没有代码补全真的可以说是灰常难受了... 洛谷P318 ...

  10. 洛谷 - 试炼场(全部题目备份)

    整理的算法模板合集: ACM模板 目录 1.新手村 1 - 1 洛谷的第一个任务 1 - 2 顺序与分支 1 - 3 循环!循环!循环! 1 - 4 数组 1 - 5 简单字符串 1 - 6 过程函数 ...

最新文章

  1. 推荐一款好用的搜索引擎(kngine)
  2. VC++中操作XML(MFC、SDK)
  3. qt 4.8.4 linux,Tslib和Qt 4.8.4与在开发板上的移植
  4. Gateway配合sentinel自定义限流_你知道如何使用阿里Sentinel实现接口限流吗?
  5. Nested Loop,Sort Merge Join,Hash Join
  6. spring data jpa 分页查询
  7. 已知三角形三点坐标求角度_细心研磨椭圆焦点三角形,这肯定是最全的解释。...
  8. git上传分支的原理_几张图让你彻底弄懂git工作流(二) ——git分支
  9. c++for循环求最大公约数_C/C++编程笔记:C语言 for 循环精讲!实例讲解带你吃透...
  10. 【opencv学习】Blob检测斑点
  11. LUOGU P3919 【模板】可持久化数组(主席树)
  12. SQLServer数据库增、删、改、查简单操作示例
  13. DPDK 中文编程指南
  14. 左耳朵耗子:云原生的正确打开方式
  15. Ctfhub解题 彩蛋
  16. Django Hello,Word!(Windows10)
  17. 亚马逊云机器人平台RoboMaker新功能WorldForge使用测试
  18. oracle 热数据,ORACLE数据库热备份步骤解析
  19. (四) 开集识别学习 open-set recognition(OSR)
  20. STM8/STM32硬件I2C读取APDS9930程序代码

热门文章

  1. 服务器CPU和普通CPU的区别
  2. 李智慧 - 架构师训练营 第三周
  3. js 判断 服务器连接状态,原生JS判断网站服务器是否开启问题及解决方案
  4. python保存视频中的每一帧
  5. css加号图标_excel单元格加号展开折叠
  6. 个人力扣刷题笔记 LCP 03. 机器人大冒险
  7. 网站报错类型及状态码总结
  8. php+dns+缓存,清理电脑dns缓存方法
  9. 达梦数据库DM8安装配置和使用
  10. tbody 不能充满table的原因