HDU 2955 Robberies (conversion probability-01 backpack)

Source: Internet
Author: User

HDU 2955 Robberies (conversion probability-01 backpack)

 

Code:

 

/** Problem: HDU No. 2955 * Running time: 46 MS * Complier: G ++ * Author: ACM_herongwei * Create Time: PM on March 9, X zeroonebags * use the probability of successful escape as a value! The total amount of money in the bank is used as the capacity of the backpack! The amount of money in a single bank, and then zeronebags */# include
 
  
# Include
  
   
# Include
   
    
# Include # define CLR (c, v) (memset (c, v, sizeof (c) using namespace std; template
    
     
Inline _ T Max (_ T a, _ T B) {return (a> B )? (A) :( B);} template
     
      
Inline _ T Maxx (_ T a, _ T B, _ T c) {return (a> Max (B, c ))? (A) :( Max (B, c);} const int N = 1e4 + 10; double dp [N]; int volume [N]; double p_value [N]; int main () {int Ncase; scanf (% d, & Ncase); while (Ncase --) {CLR (dp, 0); CLR (volume, 0 ); CLR (p_value, 0); double P; int n_banks; int sum_v = 0; scanf (% lf % d, & P, & n_banks); P = 1.0-P; // escape probability for (int I = 0; I
      
        = Volume [I]; -- j) {if (dp [j] <= dp [j-volume [I] * p_value [I]) // note that it is multiplied! {Dp [j] = dp [j-volume [I] * p_value [I] ;}} int I; for (I = sum_v; I >= 0; -- I) // calculate the probability from the forward of the total value {if (dp [I]> = P) {break ;}} printf (% d, I );} return 0;}/* sample input30.04 31 0.022 0.033 0.050.06 32 0.032 0.033 0.050.10 31 0.032 0.023 0.05 sample ouput246 */
      
     
    
   
  
 


 

 

Related Article

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.