Topic links: http://acm.hdu.edu.cn/showproblem.php?pid=1069
Simply record it
Ideas: the rectangular variety of pendulum method are stored inside the array, and then sort according to length and width, can then dp
Transfer equation DP [i] = max (DP [i], DP [T] + A [i] .Z) is stored in DP // height, a [i] .z height of the i-th
1 #include <cstdio> 2 #include <iostream> 3 #include <algorithm> 4 #include <cstring> 5 #include <string> 6 #include <stack> 7 #include <queue> 8 #include <cmath> 9 #define ll long long 10 #define pi 3.1415927 11 #define inf 0x3f3f3f3f 12 using namespace std; 13 struct node { 14 int x,y,z; 15 }a[200]; 16 bool cmp (node x, node y) 17 { 18 if (x.x==y.x) 19 return x.y<y.y; 20 return x.x<y.x; 21 } 22 int dp[200]; 23 int main () 24 { 25 int n,m,i,t,sum,j=0,k; 26 while(cin>>n) 27 { 28 j++; 29 if(n==0) 30 break; 31 k=0; 32 for(i=0;i<n;++i) 33 { 34 int x,y,z; 35 cin>>x>>y>>z; 36 if(x==y==z) 37 a[k].x=x, a[k].y=y, a[k++].z=z; 38 else if (x==y) 39 a[k].x=x, a[k].y=y, a[k++].z=z, 40 a[k].x=x, a[k].y=z, a[k++].z=y, 41 a[k].x=z, a[k].y=x, a[k++].z=y; 42 else if (x==z) 43 a[k].x=x, a[k].y=y, a[k++].z=z, 44 a[k].x=x, a[k].y=z, a[k++].z=y, 45 a[k].x=y, a[k].y=x, a[k++].z=z; 46 else if (y==z) 47 a[k].x=x, a[k].y=y, a[k++].z=z, 48 a[k].x=z, a[k].y=y, a[k++].z=x, 49 a[k].x=y, a[k].y=x, a[k++].z=z; 50 else 51 a[k].x=x, a[k].y=y, a[k++].z=z, 52 a[k].x=x, a[k].y=z, a[k++].z=y, 53 a[k].x=y, a[k].y=x, a[k++].z=z, 54 a[k].x=y, a[k].y=z, a[k++].z=x, 55 a[k].x=z, a[k].y=y, a[k++].z=x, 56 a[k].x=z, a[k].y=x, a[k++].z=y; 57 } 58 sort(a,a+k,cmp); 59 for(i=0;i<k;++i) 60 dp[i]=a[i].z; 61 int maxs=0; 62 for(i=1;i<k;++i) 63 for(t=0;t<i;++t) 64 { 65 if(a[i].x>a[t].x &&a[i].y>a[t].y){ 66 dp[i]=max(dp[i],dp[t]+a[i].z); 67 maxs=max(maxs,dp[i]); 68 } 69 } 70 cout<<"Case "<<j<<": maximum height = "<<maxs<<endl; 71 } 72 73 74 return 0; 75 }