Monkey and Banana (HDU 1069)

Source: Internet
Author: User

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&LT;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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.