Zoj 3640 probability dp, zoj3640 probability dp

Source: Internet
Author: User

Zoj 3640 probability dp, zoj3640 probability dp

Http://acm.zju.edu.cn/onlinejudge/showProblem.do? ProblemId = 4808

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

/** Zoj 3640 probability dp question: a vampire has n routes for him. Each time he takes a random route, each route has a limit, if the attack power of this vampire was greater than or equal to a certain value, it would take t days to escape. Otherwise, it would take one day and increase the attack power. Ask him the expected solution: perform the Memory search for dp [f] + = (1 + solve (f + a [I])/n; */# include <stdio. h> # include <string. h> # include <iostream> # include <algorithm> # include <math. h> using namespace std; int n, m; double a [105], dp [20005]; double solve (int f) {if (dp [f]> 0) return dp [f]; dp [f] = 0; for (int I = 0; I <n; I ++) {if (f> a [I]) {int t = (1.0 + sqrt (5)/2 * a [I] * a [I]; dp [f] + = (double) t/n ;} else {dp [f] + = (1 + solve (f + a [I])/n ;}} return dp [f] ;} int main () {while (~ Scanf ("% d", & n, & m) {for (int I = 0; I <n; I ++) {scanf ("% lf ", & a [I]);} memset (dp, 0, sizeof (dp); printf ("%. 3lf \ n ", solve (m);} 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.