HDU1069 Monkey and Banana simple DP

Source: Internet
Author: User

Test instructions

The given box (not limited to) superimposed together, the condition is that the upper box is longer and wider than the box below the length and width of the short;

The maximum height at which these boxes can be superimposed (3,2,1) can be placed (3,1,2), (2,1,3), etc.).

/************************************************author:d evilcreated TIME:2015/12/7 20:38:42***************** ******************************* */#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<queue>#include<map>#include<Set>#include<vector>#include<cstdio>using namespacestd;structwq{intA,b,c;} p[ -];intdp[ -],cnt;voidAddintXintYintz) {P[CNT].A=x; P[CNT].B=y; P[cnt++].c=Z;}BOOLCMP (Wq a,wq b) {if(A.A!=B.A)returnA.a>B.A; returnA.b>b.b;}intMain () {//freopen ("In.txt", "R", stdin);    intn,x,y,z,cas=1;  while(~SCANF ("%d", &n) &&N) {cnt=0;  for(intI=0; i<n; i++) {scanf ("%d%d%d",&x,&y,&z); if(x>y) Swap (x, y); if(x>z) swap (x,z); if(y>z) swap (y,z);            Add (x, y, z);            Add (y,z,x);        Add (x,z,y); } sort (P,p+cnt,cmp); dp[0]=p[0].c; intans=dp[0];  for(intI=1; i<cnt;i++) {Dp[i]=p[i].c;  for(intj=0; j<i;j++)                if(p[i].a<p[j].a&&p[i].b<p[j].b) Dp[i]=max (dp[i],dp[j]+p[i].c); Ans=Max (ans,dp[i]); } printf ("Case %d:maximum height =%d\n", cas++, ans); }    return 0;}

HDU1069 Monkey and Banana simple DP

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.