http://acm.hdu.edu.cn/showproblem.php?pid=1069
This means that given n types of chests, each box has an infinite number of boxes, each with three parameters (x, y, z) to determine.
You can choose any of the two parameters as long and wide, and the third one is high.
Then asked to put the box up, so that the height of the highest.
The premise of the case is the length and width of the box below > the box above.
Ideas:
Because the same box can produce 6 different boxes, and each of the most selected, because the same box at most can only be set up one.
So you can get all the boxes out, sort of, is the LIS topic.
Dp[i] represents with I this box for the maximum height of the end.
#include <cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#defineIOS Ios::sync_with_stdio (False)using namespacestd;#defineINF (0X3F3F3F3F)typedefLong Long intLL; #include<iostream>#include<sstream>#include<vector>#include<Set>#include<map>#include<queue>#include<string>Const intMAXN =100000+ -;intN;structNode {intL, W, H; Node (intLL,intWwintHH): L (LL), W (WW), H (HH) {} node () {}BOOL operator< (Const structNode & RHS)Const { if(L! = RHS. LreturnL >RHS. L Else if(W! = RHS. WreturnW >RHS. W Else returnH >RHS. H }}A[MAXN];intDP[MAXN];BOOLisOKintOneintBoth ) { if(A[one]. L > A[two]. L && A[one]. W > A[two]. Wreturn true; Else return false;}voidWork () {intt =0; for(inti =1; I <= N; ++i) {intx, y, Z; CIN>> x >> y >>Z; a[++T] =node (x, y, z); a[++T] =node (x, z, y); a[++T] =node (y, x, z); a[++T] =node (y, z, x); a[++T] =node (z, x, y); a[++T] =node (z, y, x); } sort (A+1, A +1+t); for(inti =1; I <= t; ++i) {Dp[i]=A[i]. H for(intj =1; J < I; ++j) {if(isOK (J, i)) {Dp[i]= Max (Dp[i], dp[j] +A[i]. H); } } } intAns =-inf; for(inti =1; I <= t; ++i) {ans=Max (ans, dp[i]); } Static intf =0; printf ("Case %d:maximum height =%d\n", ++F, ans);}intMain () {#ifdef local freopen ("Data.txt","R", stdin);#endif//IOS; while(Cin >> N &&N) work (); return 0;}
View Code
HDU 1069 Monkey and Banana DP lis deformation problem