A variety of methods, I do with DP.
I do it as the longest descending subsequence. Asked the other person, there is a tree DP, there are differential constraints with the shortest.
There are two-dimensional knapsack problems.
The longest monotone subsequence, with a length-width high of x, Y, and Z, is enumerated as six. Then sort, and find the longest monotone subsequence.
#include <cstdio> #include <cstring> #include <string> #include <queue> #include <algorithm > #include <map> #include <stack> #include <iostream> #include <list> #include <set># include<bitset> #include <vector> #include <cmath> #define INF 0x7fffffff#define EPS 1e-8#define LL Long Long#define PI 3.141592654#define CLR (A, B) memset (A,b,sizeof (a)) #define for (I,A,B) for (int i=a;i<b;i++) #define For_ (I,A,B) for (int i=a;i>=b;i--) #define PUB push_back#define PUF push_front#define pob pop_back#define pof pop_front #define MP make_pair#define ft first#define SD second#define SF scanf#define PF printf#define sz (v) ((int) (v). Size ()) #defi NE All (v) (v). Begin (), (v). End () #define ACFUN Std::ios::sync_with_stdio (false) #define SIZE +1using namespace std; struct point{int x, y, Z; void init (int xx,int yy,int zz) {x=xx,y=yy,z=zz; } friend bool operator < (point A,point b) {if (a.x==b.x) {if (a.y==B.Y) return a.z>b.z; Return a.y>b.y; } return a.x>b.x; }}l[size];int n;int Dp[size];int Main () {int cs=1; while (~SF ("%d", &n), n) {int m=0; for (i,0,n) {int x, y, Z; SF ("%d%d%d", &x,&y,&z); L[m++].init (x, y, z); L[m++].init (X,z,y); L[m++].init (Y,X,Z); L[m++].init (Y,Z,X); L[m++].init (Z,x,y); L[m++].init (Z,Y,X); } sort (l,l+m); CLR (dp,0); for (I,0,m) {for (j,i+1,m) {if (L[J].X<L[I].X&&L[J].Y<L[I].Y) Dp[j]=max (DP[J],DP[I]+L[I].Z); }} int ans=0; for (i,0,m)//pf ("%d \ n", dp[i]+l[i].z); Ans=max (ANS,DP[I]+L[I].Z); PF ("Case%d:maximum height =%d\n", Cs++,ans); }}
POJ 2241 The Tower of Babylon (UVA 437)