http://acm.hdu.edu.cn/showproblem.php?pid=1069
Title Description:
give you n a box, give you the length and width of the box, the box can be unlimited use, ask these boxes stacked up to how high? These boxes are stacked up with a rule that the length and width of the box below must be greater than the length and width of the box above. DP Idea: Dp[i] represents the maximum height at which the first box is stacked at the top.
#include <iostream>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<queue>#include<vector>#include<algorithm>using namespacestd;#defineEPS 1e-6#defineINF 0x3f3f3f3f#defineN 1000#defineMet (A, B) (Memset (A,b,sizeof (a)))structbox{intL, W, H; Box (intLl=0,intww=0,intHh=0): L (LL), W (WW), H (HH) {if(l>W) Swap (L, W); } BOOLFriendoperator<(Box n1, box n2) {if(N1. L! =n2. L)returnN1. L >n2. L Else if(N1. W! =n2. W)returnN1. W >n2. W returnN1. H >n2. H }}a[n]; intDp[n];intMain () {intN, icase=1; while(SCANF ("%d", &N), N) {intI, J, X, Y, Z, k=0, Max =0; Met (A,0); Met (DP,0); for(i=0; i<n; i++) {scanf ("%d%d%d", &x, &y, &z); A[k++] =Box (x, y, z); A[k++] =Box (x, z, y); A[k++] =Box (y, z, x); } sort (A, a+k); for(i=0; i<k; i++) {Dp[i]=A[i]. H for(j=0; j<i; J + +) { if(A[i]. L<A[J]. L && A[i]. w<A[j]. W) Dp[i]= Max (Dp[i], dp[j] +A[i]. H); } Max=Max (max, dp[i]); } printf ("Case %d:maximum height =%d\n", icase++, Max); } return 0;}
Monkey and Banana (HDU 1069)