Zoj3640-help Me Escape

Source: Internet
Author: User

Help Me Escape Time limit: 2 Seconds Memory Limit: 32768 KB Background

    if thou doest well, shalt thou not being accepted? and If thou do EST not well, sin lieth at the door. and unto thee shall is his desire, and thou shalt rule over him.
    and Cain talked with Abel he brother:and it came to pass while 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 is hast thou done? The voice of thy brother's blood crieth unto me from the gro und.
    and now Art thou cursed from the earth, which hath opened she mouth to receive thy brother ' s B Lood from thy hand;
    when thou tillest the ground, it shall not henceforth yield unto thee she strength; a fugitive And a vagabond shalt thou is in the earth.

--bible Chapter 4

Now Cain are unexpectedly trapped in a cave with N paths. Due to Lord's punishment, all the paths is zigzag and dangerous. The difficulty of the ith path is ci .

Then we define as the f fighting capacity of Cain. Every day, Cain is sent to one of the N paths randomly.

Suppose Cain is in front of the ith path. He can successfully take days to escape from the cave as long as his ti fighting capacity is f larger than ci . Otherwise, he has to keep trying day after day. However, if Cain failed to escape, his fighting capacity would increase as the ci result of actual combat. (A kindly reminder:cain would never died.)

tiAs for, we can easily draw a conclusion that's ti closely related to ci . 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, the positive integers N f and ( n ≤100, f ≤10000) is given in the first line. The second line includes N positive integers ci ( ci ≤ 10000, 1≤ i ≤n)

Output

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

Sample Input
3 11 2 3
Sample Output
6.889
The main topic: There are N Road, each road has a CI value, now a person to pick a path to escape. The probability of each route is the same, at the beginning this person has an F value, he randomly pick a path. Assuming that the F value is greater than CI then he needs to spend ti days to escape, assuming less then the size of f growth ci, then repeat the process, ask to escape the mathematical expectation of the number of days required
Practice: Dp[f] said that at the moment this person's combat effectiveness is f to escape the need for the number of days, transfer is n.

。。

#include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <string > #include <algorithm> #include <queue> #include <cmath>using namespace std;const int maxn = 100000+    10;struct path{int c,t; path (int c,int t): C (c), T (t) {}};vector<path> vp;int n,f;double dp[maxn];bool vis[maxn];d ouble dfs (int f) {if (vis[f    ]) return dp[f];    VIS[F] = 1;    Double ans = 0;        for (int i = 0; i < n; i++) {if (vp[i].c >= f) {ans + = (1+dfs (F+VP[I].C))/n;        }else{ans + = double (vp[i].t)/n; }} return Dp[f] = ans;}        int main () {while (~scanf ("%d%d", &n,&f)) {vp.clear ();        memset (vis,0,sizeof Vis);            for (int i = 0; i < n; i++) {int t;            scanf ("%d", &t);            int k = Int ((1+SQRT (5.0))/2*t*t);        Vp.push_back (Path (t,k));    } printf ("%.3lf\n", DFS (f)); } return 0;}


Zoj3640-help Me Escape

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.