DP stores stones in the queue by three sides and sorts the blocks by the bottom area. DP sets the maximum height and sets the longest path of the nested rectangle.
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace STD; struct tone {int x, y, z; void T (int, int B, int c) {x = A; y = B; Z = C ;}}; bool CMP (tone Q, tone p) {return Q. x * q. Y <p. x * P. y;} tone TT [100]; int DP [101]; int main () {int N; int CA = 1; while (scanf ("% d", & N) & N) {int K = 0; For (INT I = 0; I <n; I ++) {int A, B, C; scanf ("% d", & A, & B, & C); TT [k ++]. T (A, B, C); TT [k ++]. T (B, c, a); TT [k ++]. T (C, A, B);} Sort (TT, tt + k, CMP); int _ max = 0; For (INT I = 0; I <K; I ++) {DP [I] = TT [I]. z; For (Int J = 0; j <I; j ++) {If (TT [I]. x> TT [J]. X & TT [I]. y> TT [J]. y) | (TT [I]. x> TT [J]. Y & TT [I]. y> TT [J]. x) {DP [I] = max (DP [I], DP [J] + TT [I]. z) ;}}_ max = max (_ max, DP [I]);} printf ("case % d: maximum height = % d \ n", CA ++, _ max);} return 0 ;}