Hdu 3853 LOOPS (expected)

Source: Internet
Author: User

Hdu 3853 LOOPS (expected)

 

The expectation of power consumed from [1, 1] to [r, c] is calculated. The power consumed by each step is 2, from [I, j] to [I, c, j], [I, j + 1], [I + 1] [j] probability.

 

Dp [I] [j] indicates the expectation of power consumption from [I, j] to [r, c]. It is known that the final dp [r] [c] = 0, then, push back.

It is hard to think that when the probability of in-situ is 1, it cannot go through [r, c], and the result in the state transition equation is INF, which is in conflict with the requirements of the question.

 

 

# Include
 
  
# Include
  
   
# Include
   # Include
    
     
# Include
     
      
# Include
      
        # Include
       
         # Include
        
          # Include
         
           # Include
          
            # Include
           
             # Include
            
              # Include // # define LL _ int64 # define LL long # define eps 1e-9 # define PI acos (-1.0) using namespace std; const int INF = 0x3f3f3f3f; const int maxn = 4010; double dp [1010] [1010]; double a [1010] [3010]; int main () {int n, m; while (~ Scanf (% d, & n, & m) {for (int I = 1; I <= n; I ++) {for (int j = 1; j <= 3 * m; j ++) scanf (% lf, & a [I] [j]);} memset (dp, 0.0, sizeof (dp )); dp [n] [m] = 0; int flag = 1; for (int I = n; I> = 1; I --) {for (int j = m; j> = 1; j --) {if (I = n & j = m) continue; if (fabs (1.0-a [I] [(J-1) * 3 + 1]) <eps) // key {continue ;} dp [I] [j] = (dp [I] [j + 1] * a [I] [3 * (J-1) + 2] + dp [I + 1] [j] * a [I] [j * 3] + 2)/(1.0-a [I] [(J-1) * 3 + 1]);} if (flag = 0) break;} printf (%. 3lf, dp [1] [1]);} 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.