Title: http://acm.hdu.edu.cn/showproblem.php?pid=1069
The problem is quite simple, given a box of the length of the height, request the box, but must ensure that the length and width of the box below must be larger than the box above.
A box, there are six cases, after sorting, according to the longest ascending sub-sequence to solve the line.
The code is as follows:
#include <iostream>#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>#defineINF 0x3f3f3f3ftypedefLong Longll;using namespacestd;intn,tt,dp[ About];structnode{intx, Y, Z;} q[ About];intcmpConst void*AA,Const void*b) { structNode *a= (structNode *) AA; structNode *b= (structNode *) BB; if(a->x!=b->x)returnB->x-a->x; Else if(a->y!=b->y)returnB->y-a->y; Else returnB->z-a->Z;}intMain () {intk=0; intXx,yy,zz; intMaxx; while(SCANF ("%d", &n)!=eof&&n!=0) { ++K; TT=1; Maxx=-inf; for(intI=0; i<n; i++) {scanf ("%d%d%d",&xx,&yy,&ZZ); q[tt].x=xx; Q[tt].y=yy; Q[tt++].z=ZZ; q[tt].x=xx; Q[tt].y=ZZ; Q[tt++].z=yy; q[tt].x=yy; Q[tt].y=xx; Q[tt++].z=ZZ; q[tt].x=yy; Q[tt].y=ZZ; Q[tt++].z=xx; q[tt].x=ZZ; Q[tt].y=xx; Q[tt++].z=yy; q[tt].x=ZZ; Q[tt].y=yy; Q[tt++].z=xx; } qsort (Q+1, tt+1,sizeof(q[1]), CMP); Memset (DP,0,sizeof(DP)); dp[1]=q[1].z; Maxx=max (maxx,q[1].z); for(intI=2; i<tt;i++) { for(intj=1; j<i;j++) { if(q[i].x<q[j].x&&q[i].y<q[j].y) {Dp[i]=Max (dp[i],dp[j]); }} Dp[i]=dp[i]+q[i].z; Maxx=Max (maxx,dp[i]); } printf ("Case %d:maximum height =%d\n", K,maxx); } return 0;}
Hdu1069:monkey and Banana (application of the longest ascending subsequence)