Hdu 5135 status compression dp

Source: Internet
Author: User

Hdu 5135 status compression dp

The question is to give the most 12 sides. You ask the maximum area of a triangle that can be formed (multiple triangles are allowed). Typical state compression (up to 12 sides)

Ideas:
Enumerate the area of all possible triangles in a brute force manner, and then compress the area based on the state to form up to n/3 triangles. Each triangle is recorded on three sides or (operation) merge with area and then determine (based on and calculate ).


#include
 
  #include
  
   #include
   
    #include
    
     using namespace std
     ;double dp
     [1
     <<14
     ];double max
     (double a
     ,double b
     ){    return a
     >b
     ?a
     :b
     ;}struct node
     {    int pp
     ;    double area
     ;}cont
     [1
     <<14
     ];int main(){    int n
     ,i
     ,j
     ,k
     ;    int num
     [15
     ];    double S
     ;    while(~scanf
     ("%d"
     ,&n
     ),n
     )    {        for(i
     =1
     ;i
     <=n
     ;i
     ++)        scanf
     ("%d"
     ,&num
     [i
     ]);        memset
     (dp
     ,0
     ,sizeof(dp
     ));        int t
     =0
     ;        S
     =0
     ;        for(i
     =1
     ;i
     <=n
     ;i
     ++)        for(j
     =i
     +1
     ;j
     <=n
     ;j
     ++)        {            for(k
     =j
     +1
     ;k
     <=n
     ;k
     ++)            {                if(num
     [i
     ]+num
     [j
     ]>num
     [k
     ]&&num
     [i
     ]+num
     [k
     ]>num
     [j
     ]&&num
     [j
     ]+num
     [k
     ]>num
     [i
     ])                {                    double p
     =1.0
     *(num
     [i
     ]+num
     [j
     ]+num
     [k
     ])/2
     ;                    t
     ++;                    double s
     =sqrt
     (p
     *(p
     -num
     [i
     ])*(p
     -num
     [j
     ])*(p
     -num
     [k
     ]));                    cont
     [t
     ].pp
     =(1
     <<i
     )|(1
     <<j
     )|(1
     <<k
     );                    dp
     [(1
     <<i
     )|(1
     <<j
     )|(1
     <<k
     )]=cont
     [t
     ].area
     =s
     ;                }            }        }        for(i
     =1
     ;i
     <(1
     <<(n
     +1
     ));i
     ++)        {            for(j
     =1
     ;j
     <=t
     ;j
     ++)            {                if((i
     &cont
     [j
     ].pp
     )==0
     )                {                    dp
     [i
     |cont
     [j
     ].pp
     ]=max
     (dp
     [i
     |cont
     [j
     ].pp
     ],dp
     [i
     ]+cont
     [j
     ].area
     );                    if(dp
     [i
     |cont
     [j
     ].pp
     ]>S
     ) S
     =dp
     [i
     |cont
     [j
     ].pp
     ];                }            }        }        printf
     ("%.2lf\n"
     ,S
     );    }    return 0
     ;}
    
   
  
 

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.