HDU-1069 Monkey and Banana

Links : http://acm.hdu.edu.cn/showproblem.php?pid=1069

The meaning of problems : n kinds of rectangular block, dimensions x, y, z, according to the length and width requirements stacked strictly decreasing (not equal), can be folded up to ask how high

Thinking : due to one of three pieces of wood stacked manner, the one kind of wood to be copied into three candidate set is added, let long x, y is the width, z is high, the problem turned into a wood taken the decline sequence x, y is also declined sequence, and z, and the largest, linked to fat mice that question this is the bare question, ah , give x ordering, x is the drop sequence, then this sequence of seeking y the longest decline sequences. The longest decline sequences can refer to this topic

Code :

 1 #include<bits/stdc++.h>
 2 // #include<iostream>
 3 // #include<cstdio>
 4 // #include<cmath>
 5 #define inf 0x3f3f3f3f
 6 using namespace std;
 7 
 8 typedef long long ll;
 9 typedef long double ld;
10 
11 const int M = int(1e5)*3 + 5;
12 const int mod = 10056;
13 
14 inline int lowbit(int x) {
15     return x & (-x);
16 }
17 
18 struct node{
19     ll x,y,z;
20 };
21 vector<node> v;
22 
23 int n,kase;
24 ll ans;
25 ll dp[M];
26 
27 void add(int& x,int& y,int& z){
28    if(x>y) swap(x,y);
29    if(y>z) swap(y,z);
30    if(x>y) swap(x,y);
31    v.push_back({z,y,x});
32    v.push_back({z,x,y});
33    v.push_back({y,x,z});
34 }
35 bool cmp(node a,node b){
36     return a.x==b.x?a.y>b.y:a.x>b.x;
37 }
38 int main(){
39     while(cin>>n && n){
40         ans=0;
41         v.clear();
42 
43         while(n--){
44             int x,y,z;
45             cin>>x>>y>>z;
46             add(x,y,z);
47         }
48 
49         sort(v.begin(),v.end(),cmp);
50         // printf(" x   y   z \n");
51         // for(auto x:v) printf("%3d %3d %3d\n",x.x,x.y,x.z);
52 
53         int N=v.size();
54         for(int i=0;i<N;i++) dp[i]=v[i].z;
55 
56         for(int i=0;i<N;i++){
57             // printf("%d:%d %d %d\n",i,v[i].x,v[i].y,v[i].z);
58             for(int j=i-1;j>=0;j--){
59                 // printf("\t%d:%d %d %d",j,v[j].x,v[j].y,v[j].z);
60                 if(v[i].x<v[j].x && v[i].y<v[j].y){
61                     dp[i]=max(dp[i],dp[j]+v[i].z);
62                 }
63                 // printf(" %d\n",dp[j]);
64             }
65         }
66 
67         for(int i=0;i<N;i++){
68             ans=max(ans,dp[i]);
69         }
70 
71         printf("Case %d: maximum height = %d\n",++kase,ans);
72     }
73     return 0;
74 }

Note : the difficulty is one kind of think there are three pieces of wood pendulum method, I think six pendulum method

Guess you like

Origin www.cnblogs.com/harutomimori/p/11287500.html