UVA10900 So you want to be a 2n-aire?

So you want to be a 2n-aire?

PDF
in a television entertainment programs, you initially have a dollar. N moderator will ask you a question, there are two options every time you hear the questions: First, answer this question to give up, quit the game, take the prize; the second is to answer questions. If the answer is correct, the bonus is doubled; if the answer wrong, the game is over, you can not get a penny. If correctly answering all n question, you will take away all the \ (2 ^ n \) dollars, becoming the \ (2 ^ n \) dollar millionaire. Of course, to answer questions is risky. After each hearing problem, you can immediately estimate the probability of correct answers. As the host will randomly ask questions, you may think the probability of correct answers each question evenly distributed between t and 1. Enter integer n and real numbers t (1≤n≤30,0≤t≤1), your task is to find the optimal strategy under expectations, took the prize amount. Here is the best strategy to make the expected value of the bonus as large as possible.

Staginner solution to a problem of

"Training Guide" P335.
This topic is a problem from the start thinking, problem-solving and later combined with reports of view of others, and finally understand how it happens, but suddenly found that I fit seemingly risky but not for gambling ......

We wish to set up a [i] indicates the proper finish expected return of the i-question, obviously we last requirement is a [0] slightly, but the put first, let's talk about doing i + 1-Ge currently we answer the question is to choose it or choose to give it.

First, we can intuitively think, if done on the topic i quit, then you can get 2 ^ i so much money. Let's assume that the probability of correct answers the first question i + 1 Ge is p, then we naturally think of the answer expressed the expectation that the benefits obtained by multiplying p "some value", the value is multiplied if p is greater than 2 ^ i, then we We will choose the answer slightly, as if this answer desired benefits are greater than not the answer. So now the question becomes, what is this "certain value" is it? The maximum possible value? Minimum possible? Or the average (or desirable)?

If to be a metaphor, the maximum value is selected mad adventure, the minimum value is selected coward, the election is the average received ACMer good higher education, at the beginning I became a mad adventure ......

Then think about, it really is only a mean value is more convincing in statistics inside, thus the title of the so-called plays the best strategy is to go as we said above every decision whether or not to answer the answer. Above us only for p is a fixed value to discuss if we are arbitrary to a discussion of p, then the average income is clearly not the answer is constant, because it p does not matter, still 2 ^ i, if the answer, then the average earnings should be (EP + 1) / 2 a [i + 1], EP is the "watershed" we discussed earlier, is written with the expression ep = 2 ^ i / a [ i + 1], when p> ep, then p a [i + 1]> 2 ^ i, that is to say if I can answer this question to get a [i + 1] so much money, then take the answer probability p i + 1 is the first answer the question of earnings expectations, if this expectation is greater than 2 ^ i, it will choose the answer. Of course the title so that total revenue calculation, we then multiplied by the probability of each of these situations can answer or not, i.e., A [I] = (EP-T) / (. 1-T) 2 + I ^ (T-EP ) / (. 1-t) (EP +. 1) / 2 * a [I +. 1], this equation shows the value ep> t is the case, the case ep <= t, and may be similarly written expression .

Now we find, calculate a [i] is the need to use a [i + 1], then how do we do? Count backwards chant. So a [N] is the number? Apparently 2 ^ N, N-th answer because earnings after the natural question is the greatest earnings expectations.

Time complexity \ (O (n) \)

#include<bits/stdc++.h>
#define il inline
#define co const
template<class T>T read(){
    T data=0,w=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar())if(ch=='-') w=-w;
    for(;isdigit(ch);ch=getchar()) data=data*10+ch-'0';
    return data*w;
}
template<class T>il T read(T&x) {return x=read<T>();}
typedef long long LL;

co int N=35;
double d[N];
int main(){
    int n;
    double t;
    while(scanf("%d%lf",&n,&t)==2&&n){
        d[n]=1<<n;
        for(int i=n-1;i>=0;--i){
            double p0=(double)(1<<i)/d[i+1];
            if(p0<t) p0=t;
            double p1=(p0-t)/(1-t);
            d[i]=(double)(1<<i)*p1+(1+p0)/2*d[i+1]*(1-p1);
        }
        printf("%.3lf\n",d[0]);
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/autoint/p/11121695.html