HDU 1069 Monkey and Banana

参考:https://blog.csdn.net/wust_zjx/article/details/40160797

https://blog.csdn.net/a1dark/article/details/12226353

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <cstring>
 5 using namespace std;
 6 const int N=500;
 7 struct node//积木的结构体
 8 {
 9     int x,y,z;//长。宽,高
10 }no[N];
11 int dp[N];//以第i块为顶的最大高度
12 int t;
13 typedef struct node pnode;
14 bool cmp(pnode x,pnode y)
15 {
16     if (x.x>y.x)
17     {
18         return true;
19     }
20     else if(x.x==y.x&&x.y>y.y)
21     {
22         return true;
23     }
24     else
25     {
26         return false;
27     }
28 }
29 int main()
30 {
31     int n,ca=1;
32     while (cin>>n,n)
33     {
34         int x,y,z;
35         t=0;
36         for (int i=0;i<n;i++)
37         {
38             cin>>x>>y>>z;//每组值有6种组合
39             no[t].x=x,no[t].y=y,no[t++].z=z;
40             no[t].x=y,no[t].y=x,no[t++].z=z;
41             no[t].x=x,no[t].y=z,no[t++].z=y;
42             no[t].x=z,no[t].y=x,no[t++].z=y;
43             no[t].x=y,no[t].y=z,no[t++].z=x;
44             no[t].x=z,no[t].y=y,no[t++].z=x;
45         }
46         sort(no,no+t,cmp);
47         memset(dp,0,sizeof(dp));
48         for (int i=0;i<t;i++)
49         {
50             dp[i]=no[i].z;
51         }
52         for (int i=0;i<t;i++)
53         {
54             for (int j=0;j<=i;j++)
55             {
56                 if (no[j].x>no[i].x&&no[j].y>no[i].y&&dp[j]+no[i].z>dp[i])//注意i,j不要写错!
57                 {
58                     dp[i]=dp[j]+no[i].z;
59                 }
60             }
61         }
62         int ans=0;
63         for (int i=0;i<t;i++)
64         {
65             ans=max(ans,dp[i]);
66         }
67         cout<<"Case "<<ca++<<": maximum height = "<<ans<<endl;
68     }
69 
70     return 0;
71 }
原文地址:https://www.cnblogs.com/hemeiwolong/p/9441176.html