Because each block has an infinite number of blocks, so (x, Y, z) is equivalent to the three blocks of (x, Y, z) + (x,z,y) + (y,z,x).
It is then solved like a rectangular nesting, except that the state transition equation becomes:
Dp[i] = max (Dp[i], dp[j] + z[i]);
The code is as follows:
1#include <algorithm>2#include <cstdio>3 using namespacestd;4 5 Const intN = -;6 intDp[n];7 8 structNode9 {Ten intx, y, Z; One BOOL operator< (ConstNode & O)Const A { - if(x! = o.x)returnX <o.x; - returnY <o.y; the } - Node () {} -Node (int_x,int_y,int_z) - { +x = _x, y = _y, z =_z; - } + voidStandard () A { at if(X >y) Swap (x, y); - } - } Node[n]; - - intMain () - { in intN, _case =1; - while(SCANF ("%d", &N), N) to { + for(inti =0; I < n; i++ ) - { the intx, y, Z; *scanf"%d%d%d", &x, &y, &z); $Node[i *3] =Node (x, y, z);Panax NotoginsengNode[i *3].standard (); -Node[i *3+1] =Node (x, z, y); theNode[i *3+1].standard (); +Node[i *3+2] =Node (y, z, x); ANode[i *3+2].standard (); the } +Sort (node, node +3*n); - intAns =-1; $ for(inti =0; I <3N i++ ) $ { -Dp[i] =node[i].z; - for(intj =0; J < I; J + + ) the { - if(Node[j].x < node[i].x && Node[j].y <node[i].y)Wuyi { theDp[i] = max (Dp[i], dp[j] +node[i].z); - } Wu } -Ans =Max (ans, dp[i]); About } $printf"Case %d:maximum height =%d\n", _case++, ans); - } - return 0; -}
Hdu 1069 Longest ascending sub-sequence variants