Uva10900-so want to be a 2n-aire? Expectations

Source: Internet
Author: User

We may as well set a[i] to say that the expectation of the proceeds of the first question is done correctly, and obviously the last thing we ask for is a[0], but this one first, let's talk about the question before we do the first i+1, we choose to answer or choose to give up.

First of all, we can intuitively think that if you finish the I question on the exit, you can get 2^i so much money. Suppose that the probability of the answer to the i+1 question is P, then we naturally think of using p multiplied by "some value" to indicate the return of the results obtained by the expectation, if p multiplied by this value is greater than 2^i, we will certainly choose to answer, because if the answer to the result is greater than the expectation of the return of the answer. So now the question is, what is this "some value"? What is the maximum possible value? The minimum possible value? Or is it an average (or an expectation)?

If you make a metaphor, choose the maximum is the risk of madness, choose the minimum is the timid ghost, the average choice is to receive a good higher education acmer, at first I became a risk-averse ...

Later think, also really only average in statistics inside is more persuasive, so the title of the so-called plays the best strategy is according to what we said above to decide each time is the answer or not answer. Above we are only for the fixed value of P is discussed, if we to the P is arbitrary to discuss, obviously do not answer the average return is unchanged, because it does not matter with P, is still 2^i, if the answer to the average profit should be (ep+1)/2*A[I+1],EP is the "watershed" we discussed earlier , write with the expression is ep=2^i/a[i+1], when P>ep, then P*a[i+1]>2^i, that is, if the answer to this question I can get a[i+1] so much money, and then the probability p is the answer i+1 question of the revenue expectations, If this expectation is greater than 2^i, then the answer will be chosen. Of course, let's calculate the total revenue, we multiply the probability of each of these cases, namely a[i]= (EP-T)/(1-T) *2^i+ (T-EP)/(1-T) * (ep+1)/2*a[i+1], this sub-value lists the situation of ep>t, For ep<=t, you can also write an expression like this.

Now we find that calculating a[i] is needed for a[i+1], so what do we do? Count it upside down. So how much is a[n]? Obviously it is 2^n, because the expectation of return after the nth question is naturally the greatest benefit.

#include <stdio.h> #include <string.h> #include <math.h> #define MAXD 35int n;double t,q[maxd];void Solve () {    int i,j,k;    Double eq,f=1,quit;    F=q[n];    for (i=n-1;i>=0;i--) {        quit=q[i];        eq=quit/f;        if (eq<=t)            f= (t+1)/2*f;        else            f= (eq-t)/(1-T) *quit+ (1-EQ)/(1-T) * (eq+1)/2*f;    }    printf ("%.3lf\n", f);} int main () {    q[0]=1;    for (int i=1;i<=30;i++)        q[i]=2*q[i-1];    for (;;) {        scanf ("%d%lf", &n,&t);        if (! N) break            ;        if (Fabs (1-t) <1e-9)            printf ("%.3lf\n", Q[n]);        else            solve ();    }    return 0;}


Uva10900-so want to be a 2n-aire? Expectations

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.