BABTWR - Tower of Babylon

题意翻译

题目: 有$n$种长方形方块,每种有无限个,第i种方块的三边边长是$x_{i}$,$y_{i}$,$h_{i}$(y是高,x是宽,z是长,但是这个不用管)。对于每一个方块,你可以任意选择一面作为底,这样高就随着确定了。 他们想要用堆方块的方式建尽可能高的塔。问题是,只有一个方块的底的两条边严格小于另一个方块的底的两条边,这个方块才能堆在另一个上面。这意味着,一个方块甚至不能堆在一个底的尺寸与它一样的方块的上面。要求计算出这个塔可以建出的最高的高度。 输入: 输入包含至少一组数据,每组数据的第一行是一个整数$n$($n$<=30),表示方块的种类数。 这组数据接下来的$n$行,每行有三个整数,表示$x_{i}$,$y_{i}$,$z_{i}$。 输入数据会以$0$结束。 输出: 对于每组数据,输出一行,表示在这个数据中,可搭出的塔最高的高度。

题目描述

![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP100/7a939db1eae2f77be9ce3ec4d462683703792d71.png)Apart from the Hanging Gardens the Babylonians (around 3000-539 b.c.) built the Tower of Babylon as well. The tower was meant to reach the sky, but the project failed because of a confusion of language imposed from much higher above. For the 2638th anniversary a model of the tower will be rebuilt. _n_ different types of blocks are available. Each one of them may be duplicated as many times as you like. Each type has a height _y_, a width _x_ and a depth _z_. The blocks are to be stacked one upon eachother so that the resulting tower is as high as possible. Of course the blocks can be rotated as desired before stacking. However for reasons of stability a block can only be stacked upon another if _both_ of its baselines are shorter.

输入输出格式

输入格式


The number of types of blocks _n_ is located in the first line of each test case. On the subsequent _n_ lines the height _y $ _{i} $_ , the width _x $ _{i} $_ and the depth _z $ _{i} $_ of each type of blocks are given. There are never more than 30 different types available. There are many test cases, which come one by one. Input terminates with n = 0. **Edited:** You can assume that max(_x $ _{i} $_ , _y $ _{i} $_ , _z $ _{i} $_ ) <= 2500.

输出格式


For each test case your program should output one line with the height of the highest possible tower.

输入输出样例

输入样例 #1

5
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
1
1 1 1
0

输出样例 #1

342
1