Hdu4800_joseph Phina and RPG (two-dimensional dp)

Source: Internet
Author: User

Hdu4800_joseph Phina and RPG (two-dimensional dp)

 

Question: The dp state is set to Use Role j to pass the maximum percentage of I (dp [I] [j])

Start with the last field:
Dp [I] [j] = rate [j] [AI [I] * max (dp [I + 1] [j], dp [I + 1] [a [I]);

That is, the maximum winning rate of using role j to pass the I-level = the winning rate of using role j to win the I-level AI * max (the probability of using j for customs clearance in the next level, the probability that AI passes through the next mark)

Set the initial value and review it.

# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       
         # Include
        
          # Include
         
           # Include
          
            # Include
           # Include
            
              # Include
             
               # Include
              
                # Include
               
                 # Include
                
                  # Include
                 
                   Using namespace std; # define mem (x, y) memset (x, y, sizeof (x) inline int lowbit (int x) {return x & (-x );} typedef long int LL; const int INF = 0x3f3f3f3f; const long double PI = acos (0.0) * 2.0; const int N = 10000 + 10; const double eps = 1e-6; double dp [N] [200], rate [200] [200]; int ai [N]; int Comb (int x, int y); int main () {int n, m; // ios: sync_with_stdio (false); // close the synchronous stream while (scanf (% d, & m) = 1) {int r = Comb (m, 3); for (int I = 0; I <r; I ++) for (int j = 0; j <r; j ++) scanf (% lf, & rate [I] [j]); scanf (% d, & n); for (int I = 0; I <n; I ++) scanf (% d, & ai [I]); mem (dp, 0.0); for (int j = 0; j <r; j ++) dp [n-1] [j] = rate [j] [ai [n-1]; for (int I = n-2; I> = 0; I --) {for (int j = 0; j <r; j ++) {dp [I] [j] = max (dp [I] [j], rate [j] [ai [I] * max (dp [I + 1] [j], dp [I + 1] [ai [I]);} double res = 0.0; for (int j = 0; j <r; j ++) res = max (res, dp [0] [j]); printf (%. 6lf, res) ;}return 0 ;}int Comb (int x, int y) {int u = 1, v = 1, len; if (y = 0 | x = y) return 1; if (y = 1) return x; if (x <y) return 0; if (y> x/2) y = len = x-y; else len = y; while (len --) {u * = x --; v * = y --;} return (int) (u/v );}
                 
                
               
              
             
            
          
         
        
       
      
     
    
   
  

 

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.