ZOJ 3640 Help Me Escape (probability dp + Memory)

Source: Internet
Author: User
Tags cmath

ZOJ 3640 Help Me Escape (probability dp + Memory)

 

Background

 

If thou doest well, shalt thou not be accepted? And if thou doest not well, sin lieth at the door. And unto thee shall be his desire, and thou shalt rule over him.
And Cain talked with Abel his brother: and it came to pass, when they were in the field, that Cain rose up against Abel his brother, and slew him.
And the LORD said unto Cain, Where is Abel thy brother? And he said, I know not: Am I my brother's keeper?
And he said, What hast thou done? The voice of thy brother's blood crieth unto me from the ground.
And now art thou cursed from the earth, which hath opened her mouth to receive thy brother's blood from thy hand;
When thou tillest the ground, it shall not henceforth yield unto thee her strength; a fugitive and a vagabond shalt thou be in the earth.

-- Bible Chapter 4

Now Cain is unexpectedly trapped in a caveNPaths. Due to LORD's punishment, all the paths are zigzag and dangerous. The difficulty ofIthPath isCi.

Then we defineFAs the fighting capacity of Cain. Every day, Cain will be sent to one ofNPaths randomly.

Suppose Cain is in front ofIthPath. He can successfully takeTiDays to escape from the cave as long as his fighting capacityFIs largerCi. Otherwise, he has to keep trying day after day. However, if Cain failed to escape, his fighting capacity wowould increaseCiAs the result of actual combat. (A kindly reminder: Cain will never died .)

AsTi, We can easily draw a conclusion thatTiIs closely relatedCi. Let's use the following function to describe their relationship:

 

 

After D days, Cain finally escapes from the cave. Please output the expectation of D.

Input

The input consists of several cases. In each case, two positive integersNAndF(N≤ 100,F≤ 10000) are given in the first line. The second line between des N positive integersCi(Ci≤ 10000, 1 ≤I≤ N)

Output

For each case, you shoshould output the expectation (3 digits after the decimal point ).

Sample Input
3 11 2 3
Sample Output
6.889

 

 

A vampire has n routes for him. Each time he takes a random route, each route has a limit. If the attack power of the vampire is greater than or equal to a certain value, it will take t days to escape. Otherwise, it will take 1 day and increase the attack power and ask him what he expects to escape.

 

 

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       
         # Include
        
          # Include
         # Define L (x) (x <1) # define R (x) (x <1 | 1) # define MID (x, y) (x + y)> 1) # define eps 1e-8 // typedef _ int64 ll; # define fre (I, a, B) for (I = a; I
          
            = A; I --) # define mem (t, v) memset (t), v, sizeof (t) # define ssf (n) scanf ("% s ", n) # define sf (n) scanf ("% d", & n) # define sff (a, B) scanf ("% d", &, & B) # define sfff (a, B, c) scanf ("% d", & a, & B, & c) # define pf printf # define bug pf ("Hi \ n") using namespace std; # define INF 0x3f3f3f3f # define N 20005 double dp [N]; int c [N]; int n; int f; double dfs (int f) {int I; if (dp [f]> 0) return dp [f]; double ans = 0; fre (I, 0, n) {If (f> c [I]) {int t = (int) (1 + sqrt (5.0)/2 * c [I] * c [I]); // The number of days it takes longer than c [I] ans + = t * 1.0/n ;} elseans + = 1.0/n * (1 + dfs (f + c [I]); // days not greater than c [I]} dp [f] = ans; return ans;} int main () {int I, j; while (~ Scanf ("% d", & n, & f) {mem (dp, 0); for (I = 0; I
           
            

 

 

 

 

 

 

 

 

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.