JZOJ 2000. [2015.8.6 universal set of simulated race] Leo building blocks

Title Description

         Leo is a happy Martian, always and OIers on Earth play very high.
         To 2012, Leo has been recalled to Mars, did not stay on Mars he played, but he had many, many blocks, he began playing with building blocks.
       The Martians were manufactured n kinds of building blocks, building blocks can be an unlimited supply. Each building block is a rectangular parallelepiped, the i-th blocks of length, width and height respectively li, wi, hi. Blocks can be rotated, so that any change length and breadth. Leo want to use these building blocks to take one of the highest tower. The problem is that, if we want a building on top of another building block, must ensure that the length and width of blocks above the following blocks are strictly less than the length and width. This means that even if the two building blocks of the same length and width can not pile up.
       No computer on Mars, kindly help you decide Leo calculated height of the tallest tower.

[Note]
Each building block can be split into three blocks respectively into height li, wi, hi, the other two sides of a length and width, to ensure long> = broad.
 

Entry

The first line, an integer n, the several blocks of
the next n lines, each line an integer of 3 li, wi, hi, building blocks represented LWH

Export

A line integer, the maximum value indicates a high tower
 

Sample input

Sample Input1:
1
10 20 30


Sample Input2:
2
6 8 10
5 5 5



Sample Input3:
5
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27

 

Sample Output

Sample Output1:
40


Sample Output2:
21


Sample Output3:
342
 

Data range limit

30% of the data for n <= 8
to 100% of the data n <= 3000, the final answer will not exceed 32-bit integer
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 struct Node{
 4     int w,l,h;
 5 }a[10001];
 6 bool bdx(Node c,Node d)
 7 {
 8     return c.l<d.l;
 9 }
10 int main()
11 {
12     freopen("brick.in","r",stdin);
13     freopen("brick.out","w",stdout);
14     int n,f[10001],ans;
15     cin>>n;
16     int o,p,q;
17     for(int i=1;i<=n;i++)
18     {
19         cin>>o>>p>>q;
20         a[i].l=max(o,p);a[i].w=min(o,p);a[i].h=q;
21         a[i+n].l=max(o,q);a[i+n].w=min(o,q);a[i+n].h=p;
22         a[i+2*n].l=max(p,q);a[i+2*n].w=min(p,q);a[i+2*n].h=o;
23     }
24     std::sort(a+1,a+3*n+1,bdx);
25     for(int i=1;i<=3*n;i++)
26         f[i]=a[i].h;
27     for(register int i=3*n;i>=1;i--)
28         for(register int j=i+1;j<=3*n;j++)
29             if(a[i].w<a[j].w && a[i].l != a[j].l)
30                 f[i]=max(f[j]+a[i].h,f[i]);
31     for(int i=1;i<=3*n;i++)
32     ans=max(ans,f[i]);
33     cout<<ans;
34 }

Guess you like

Origin www.cnblogs.com/anbujingying/p/11305439.html