Test instructions
There are N, long x width y high z box, the box stacked up, the upper box bottom of the length of the surface must be smaller than below, to the maximum height of the stack.
Analysis:
A box, you can have three kinds of discharge, first put all the state of storage, according to the bottom of ascending order, Dp[i] before I can make up the maximum height, Dp[i]=max (dp[i],dp[j]+h) h for the current box height
#include <map>#include<Set>#include<list>#include<cmath>#include<queue>#include<stack>#include<cstdio>#include<vector>#include<string>#include<cctype>#include<complex>#include<cassert>#include<utility>#include<cstring>#include<cstdlib>#include<iostream>#include<algorithm>using namespaceStd;typedef pair<int,int>Pii;typedefLong Longll;#defineLson l,m,rt<<1#defineRson m+1,r,rt<<11#defineAll 1,n,1#defineRead Freopen ("In.txt", "R", stdin)Constll infll =0x3f3f3f3f3f3f3f3fll;Const intinf=0x7ffffff;Const intMAXN = 1e5+ -;Const intMoD =1000000007;structblock{intx; inty; intZ;} b[ About];BOOLCMP (Block U,block v) {if(u.x==v.x)returnU.y>v.y; Else returnU.x>v.x;}intdp[ About],n;intSolveintnum) {memset (DP,0,sizeof(DP)); Sort (b,b+num,cmp); intma=-1; for(intI=0; i<num;++i) {Dp[i]=b[i].z; for(intj=0; j<i;++j) { if(b[j].y>b[i].y&&b[j].x>b[i].x) Dp[i]=max (dp[i],dp[j]+b[i].z); } if(dp[i]>Ma) Ma=Dp[i]; } returnMa;}intMain () {intt=0, Xx,yy,zz; while(~SCANF ("%d",&N)) { if(n==0) Break; T++; intnum=0; for(intI=0; i<n;++i) {scanf ("%d%d%d",&xx,&yy,&ZZ); b[num].x=xx;b[num].y=yy;b[num].z=ZZ; Num++; b[num].x=yy;b[num].y=xx;b[num].z=ZZ; Num++; b[num].x=zz;b[num].y=yy;b[num].z=xx; Num++; b[num].x=yy;b[num].y=zz;b[num].z=xx; Num++; b[num].x=xx;b[num].y=zz;b[num].z=yy; Num++; b[num].x=zz;b[num].y=xx;b[num].z=yy; Num++; } /*for (int i=0;i<num;++i) printf ("%d%d%d\n", b[i].x,b[i].y,b[i].z);*/printf ("Case %d:maximum height =%d\n", T,solve (num)); }return 0;}
The Tower of Babylon