Zoj 3640 Help Me Escape (expected)

Source: Internet
Author: User

Zoj 3640 Help Me Escape (expected)

 

 

This question is terrible.

A vampire is trapped and has n ways to escape. Each road has a difficulty c []. His initial combat power is f. For the I-th Road, if f> c [I], he will spend t [I] days to go out. Otherwise, he will stay for one day, increase the fighting capacity of c [I], and then select another way to go out, the probability of each route is the same. Ask him about the days he expected to escape.

If dp [I] is set to indicate the expected value of escaping when the combat capability is I, the state equation can be introduced.

Dp [I] = 1/n * t [j] (c [j]> I ), dp [I] = 1/n * (1 + dp [I + c [j]) (c [j] <= I ).

Note that the final State is determined. When f> Max, the expected value is the average value of the total time, But I + c [j] may be greater than Max + 1, so the final state should be Max * 2. During initialization, you forget to multiply by 2.

In addition, t [I] is an integer.

 

 

#include 
 
  #include 
  
   #include
   #include 
    
     #include 
     
      #include 
      
       #include 
       
        #include 
        
         #include 
         
          #include 
          
           #include 
           
            #include 
            
             #include //#define LL __int64#define LL long long#define eps 1e-8#define PI acos(-1.0)using namespace std;const int INF = 0x3f3f3f3f;const int maxn = 4010;double dp[10010];int c[110];double t[110];int main(){int n,f;int Max;double sum_t,ave_t;while(~scanf(%d %d,&n,&f)){Max = f;sum_t = 0;for(int i = 1; i <= n; i++){scanf(%d,&c[i]);t[i] = (int) ( (1+sqrt(5))*0.5*c[i]*c[i] );Max = max(Max,c[i]);sum_t += t[i];}ave_t = sum_t/n;if(f > Max){printf(%.3lf,ave_t);continue;}memset(dp,0,sizeof(dp));for(int i = Max+1; i <= 20000; i++)dp[i] = ave_t;for(int i = Max; i >= f; i--){for(int j = 1; j <= n; j++){if(i > c[j]){dp[i] += t[j];}else{dp[i] += 1+dp[i+c[j]];}}dp[i] /= n;}printf(%.3lf,dp[f]);}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.