UVa 103 - Stacking Boxes

103 - Stacking Boxes

 * http://acm.uva.es/p/v1/103.html

Summary
This is a Longest Increasing Subsequence problem, with a little twist. Sorting is required to give us the properties that allow us to make the connection.

Explanation
It should be clear that it's a Longest Increasing Subsequence problem. We want to be able to check if box a fits in box b easily. To accomplish this, we first sort on the dimensions of each box to renormalize it - giving us, for each box, the dimensions $$( s_1, s_2, s_3, ..., s_i )$$ such that $$s_i <= s_j$$ for all $$i < j$$.

Now, box a is in box b if the dimension vector of box a is less than the dimension vector of box b. ($$a < b$$ if $$a_i <= b_i$$ for all i.

Sort all the boxes using the above definition, and we can then use the Longest Increasing Subsequence algorithm. (For this problem, the $$O(n^2)$$ implementation is enough.)

Input
Input Here

Output
Output Here