No.497 Nested Boxes
Problem Statement
There are $N$ rectangular cuboid boxes of various sizes.
You want to choose some of these boxes and make nested boxes, like a matryoshka doll, by repeatedly putting a smaller box inside a larger box.
What is the maximum number of levels of nesting you can achieve?
Note the following.
Boxes may be rotated or laid on their side when used.
Box $i$ can be put inside box $j$ only if the width, depth, and height of box $i$ (after being arbitrarily rotated or laid on its side) are each strictly smaller than the width, depth, and height of box $j$, respectively.
Putting two boxes directly inside one box does not count as three levels of nesting.
Input
$N$ $X_1$ $Y_1$ $Z_1$ $X_2$ $Y_2$ $Z_2$ $\vdots$ $X_N$ $Y_N$ $Z_N$
$1 \le N \le 1000$
$1 \le X_i,Y_i,Z_i \lt 10^8$
$N, X_i, Y_i, Z_i$ are all integers.
The number of boxes is $N$.
The size of the $i$-th box is such that its three side lengths are $X_i, Y_i, Z_i$.
Output
Output, as an integer, the maximum number of levels of nesting of the boxes.
If the boxes cannot be nested at all, output $1$.
Sample
Sample 1
Input
4 2 2 2 1 1 1 3 3 3 4 1 4
Output
3
As shown in the figure below, by putting the box of size $(1,1,1)$ inside the box of size $(2,2,2)$,
and then putting that inside the box of size $(3,3,3)$, you can achieve 3 levels of nesting.
The box of size $(4,1,4)$ was not used.
(A "box of size $(X,Y,Z)$" means a box whose three side lengths are $X, Y, Z$.)
* The figure omits the representation of height.
Sample 2
Input
2 1 1 3 2 4 2
Output
2
If the box of size $(1,1,3)$ is laid on its side, it can be put inside the box of size $(2,4,2)$.
Sample 3
Input
2 5 5 3 4 3 3
Output
1
No matter how each box is oriented, neither box can be put inside the other.
Since no nesting is possible at all, the answer is $1$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
tails
conf