ZOJ 3640 help Me Escape probability DP

Source: Internet
Author: User

There is a vampire trapped, there are n ways to escape, each road has a difficulty c[], his initial combat effectiveness is F, for the first road, if f > c[i] He spent t[i] Day can go out, otherwise, he will stay one day, while fighting increased c[i] and then choose a road to go out, The probability that he walks on each road is the same. Ask him about the number of days he escaped.

Set Dp[i] Indicates the expected value of escaping at the time of fighting, then 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).

It is important to note that the final state is determined. When F > Max, the expected value for the total time is the end state, but i + c[j] may be greater than max+1, so the final state should be max*2. When initializing, you forget to multiply by 2.

And there is t[i] is an integer.




Description

Background

    if thou doest well, shalt thou isn't being accepted? and If thou doest not well, sin lieth at the D Oor. and unto thee shall be he desire, and thou shalt rule over him. 
    and Cain talked with Abe L His Brother:and it came-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 did? 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; 
    whe n 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
#include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> #include < Cstring>using namespace std;double dp[1000010];int b[110];d ouble a= (1+SQRT (5)) *0.5;int main () {    int n,f;    while (~SCANF ("%d%d", &n,&f))    {        int max=0;        for (int i=1; i<=n; i++)        {            scanf ("%d", &b[i]);            Max=max (Max,b[i]);        }        Memset (Dp,0,sizeof (DP));        for (int i=2*max; i>=f; i--)        {           dp[i]=0;            for (int j=1; j<=n; j + +)            {                if (I>b[j]) dp[i]+= (int) (a*b[j]*b[j]);                else dp[i]+= (1+dp[i+b[j]);            }            dp[i]/=n;        }        printf ("%.3lf\n", Dp[f]);    }    return 0;}


ZOJ 3640 help Me Escape probability DP

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.