Probabilistic DP zoj 3640

Source: Internet
Author: User

Help me escape Time limit:2000 ms Memory limit:32768kb 64bit Io format:% LLD & % llusubmit status practice zoj 3640 appoint description: System crawler)

Description

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

/*************************************** * *********************************> File Name: t. CPP> author: acvcia> mail: [email protected]> created time: tuesday, October 21, 2014 ******************************** **************************************** /# include <iostream> # include <algorithm> # include <cstdio> # include <vector> # include <cstring> # include <map> # include <queue> # include <Stack> # include <string> # Inc Lude <cstdlib> # include <ctime> # include <set> # include <math. h> using namespace STD; typedef long ll; const int maxn = 20000 + 10; # define rep (I, a, B) for (INT I = (); I <= (B); I ++) # define Pb push_backint N, C [105], F; double DP [maxn]; double D (INT F) {If (DP [f]> 0) return DP [f]; DP [f] = 0; For (INT I = 1; I <= N; I ++) {If (F> C [I]) {int t = (1 + SQRT (5) * C [I] * C [I]/2; DP [f] + = (double) T/N;} else {DP [f] + = (1 + d (F + C [I])/n ;}} return DP [f];} int Main (INT argc, char const * argv []) {While (~ Scanf ("% d", & N, & F) {memset (DP, 0, sizeof DP); For (INT I = 1; I <= N; I ++) scanf ("% d", C + I); printf ("%. 3f \ n ", D (f);} return 0 ;}



Probabilistic DP zoj 3640

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.