N types of blocks are provided. The maximum height of these blocks can be stacked. the length and width of the above blocks must be strictly lower than that of the bottom blocks. */[Cpp] # include <stdio. h> # include <stdlib. h> # define N 95 int f [N]; // f [N] records the maximum height after I block struct X {int x, y, z ;} block [N]; int cmp (const struct X * a, const struct X * B) {if (* ). x! = (* B ). x) return (* ). x-(* B ). x; else return (* ). y-(* B ). y;} int main () {int T, n, a, B, c, I, j, temp, tallest; T = 1; while (scanf ("% d ", & n), n) {for (I = 0, j = 0; j <n; j ++) {// each block can be scanf ("% d", & a, & B, & c); block [I]. x = a; block [I]. y = B; block [I]. z = c; block [I + 1]. x = a; block [I + 1]. y = c; block [I + 1]. z = B; block [I + 2]. x = c; block [I + 2]. y = B; block [I + 2]. z = a; I + = 3 ;}for (I = 0; I <n * 3; I ++) {// find the length and width of each block if (block [I]. x <block [I]. y) {Temp = block [I]. x; block [I]. x = block [I]. y; block [I]. y = temp ;}} qsort (block, n * 3, sizeof (block [0]), cmp); // sort by the "length" of the block in ascending order, for (I = 0, tallest = 0; I <3 * n; I ++) {// initialize f [I] to the height of I. When f [I] is calculated, traverse 0-> I to find the maximum height when I block is placed. F [I] = block [I]. z; for (j = 0; j <= I; j ++) {if (block [I]. x> block [j]. x & block [I]. y> block [j]. y) {f [I] = max (f [I], f [j] + block [I]. z);} tallest = max (tallest, f [I]);} printf ("Case % d: maximum height = % d \ n", T ++, tallest);} return 0 ;}