The conditional probability problem in a game

Source: Internet
Author: User
Tags random seed

Let's say you're on a game show. Three doors are now available for you to choose from: one door behind it is a grand prize (such as the Audi R8), and the other two doors have no horses behind them. You don't have to, so your goal is certainly to win the jackpot, but you obviously don't know what's behind the door. The host (although Ta know what is behind the door, but TA is not telling you) first let you do the first choice. After you have chosen a door, the host does not immediately open the door, but opens another wood-winning door for you to see. Now, the host tells you that you have a chance to re-choose. So, please think about it, do you insist on the choice of the first time, or change the first choice? Which approach is more likely to win the jackpot?

This question seems very simple: the host ruled out a door without a prize before making a choice is three election, the probability of winning is 1/3, and after the exclusion is two election, the probability of winning is 1/2, obviously > 1/3, so the chance to change the prize is greater.

But in fact this algorithm is not exactly correct. Insist on the first choice of the same, the probability of winning is 1/3, but change the first choice, the probability of winning is not 1/2, but 2/3!

Do you believe me?

Students who do not believe may wish to look at the results of the poor lifting method:

A B C
Y N N
1 2 X
2 1 X
2 X 1

Note: A,b,c stands for three different doors; y means the door has a big prize, n means the gate is a trophy; 1 means the first choice, 2 means the second choice; x means the door is excluded by the host and cannot be played in the end.

If the choice persists for the first time, then just look at the part with 1: In three 1, with a column of Y (that is, winning) only one, so the probability of winning is 1/3.

If you change the choice for the first time, then just look at the part with 2: In three 2, there are two with the Y column, so the probability of winning is 2/3, not 1/2.

This poor lifting method has a condition: the inside of the 1 can not appear in the same row (this case violates the logic), it is best not to appear in the same column, so as to ensure that each 1 probability is equal, or the basis of the number calculation probability is wrong.

In fact, this is a "conditional probability" calculation. You first choose a door, each door is selected the probability is 1/3, and then based on your choice of this precondition, the host then select a door. If you choose a door without a prize for the first time, then the condition probability of the host choosing a door without a prize is 1, and the joint probability is 1/3; If you choose a prize-winning door for the first time, the probability of the host choosing a door without an award is 1/2, and the joint probability is 1/3*1/2=1/6. Therefore, do not change the probability of winning is 1/6+1/6=1/3, the probability of winning is 1/3+1/3=2/3.

Hey, God, the horse will be like this? Hey, God, the horse is 2/3, not 1/2? Because in addition to the obvious limitations of the moderator's exclusion of a door, there is an implicit constraint: Change the first choice. That is, as long as you change the first choice, then you are not in the left of the "two" door to choose between, you have only one door optional. At this point, you are more likely to be against the previous self: If you have a 1/3 chance of winning the previous choice, then after the change of choice, you will have a 1/3 probability of passing with the jackpot, if your choice before the probability of 2/3, then change the choice, then you have a 2/3 chance to take the jackpot home. (see these two words is a sentence of the classmate, congratulations!) You can go to this kind of game! )

Speaking of which, whether you understand it or not, I will continue to say. Maybe if you look down a little bit, you'll understand.

What if the three doors were extended to four doors that would be God-horse?

A B C D
Y n n N
1 2 X 2
2 1 X 2
2 X 1 2
2 2 X 1

Using the above-mentioned method, we know that the winning probability of insisting on the first choice is 1/4, and the winning probability of changing the first choice is 3/8, not 1/3=3/9 (hello God ma so write?) and see below * * place). Obviously, the host excludes a door, and after you change the previous selection, you only have the door (4-1-1) that you can really freely choose (not 3), and their probabilities are equal to 1/(4-1-1) =1/2. If you want to win, then your first choice must be wrong, no prize, this probability is (1-1/4) =3/4. Therefore, the probability of changing the first choice and winning the prize is (3/4) * (1/2) =3/8.

If you continue to extrapolate, the five-door situation is: The winning probability of not changing the selection is 1/5, the winning probability of the change is (1-1/5) *{1/(5-1-1)}=4/15, not 1/4=4/16.

The case of six doors is ... You ask Guo Furong her father Guo!

In addition, you do not have to worry about the 27 doors when there is no English letter to represent the door (note, I did not mention the representatives), because when you study 14 doors, you will find that this is the case of n-door! This is a good gospel for those of you who are trying to continue to study with the above-mentioned method of exhaustion.

Using the mathematical induction method can be proven (do not need other advanced math skills, sexual interested students can solve their own hands), N-door situation is, adhere to the winning probability is 1/n, change the probability of winning is (1-1/n) *{1/(n-1-1)}= (N-1)/{n* (N-2)}. where n is a positive integer greater than or equal to 3. Another kind of induction here is: (N-1)/{(N-1) ^2-1)}= (N-1)/{n* (N-2)}.

Obviously, (N-1)/(N-2) >1, so change the first choice and the probability of winning more than adhere to the first choice of winning probability. Therefore, in the future you take part in this kind of cheap game, the principle is must change!

Speaking of which, if you don't understand, please go back to the six doors.

To promote the above problem a little more, we can get a more ordinary conclusion:

Give you n door, where M is prize-winning, the rest of the prize, you choose a fan, and then the host opened the other L Fan no award for you to see, and let you re-select a door. At this time, insist on not changing the door and the probability of winning is m/n; the probability of winning for another door is {m* (n-m)}/{n* (N-L-1)}. Among them, n,m,l are positive integers, and n>2, (m+l) <n.

How did you get that? It can be understood that: Obviously the first choice of the winning probability is m/n, then change the first choice means to abandon the m* (m/n) award, and the remaining {m-m* (m/n)} a grand prize. You have to choose one of the remaining doors, at which point the probability of winning is {m-m* (m/n)}/(N-L-1) ={m* n-m (}/{n*)} n-l-1.

in this case, how to win the prize will see (L+1) and M who is big. when the l+1 is larger than M, the probability of changing the previous selection is greater; Conversely, when the l+1 than M hours, adhere to the original choice of winning probability is higher; if l+1=m, then change does not matter, the probability is equal.

Finally, I say one more point (you can stick to this to show that you are really rational), here can also come up with a more ordinary inference, that is, the first time you can choose K-door, and the second can choose J-door, where k+j+l<n.

Then insist on the first choice of the same winning probability is:

(1-m/n) ^k

The odds of winning the first choice are:

1-{1-m*z/(N-L-K)}^j, wherein, z= (1-m/n) ^k

Is this the time to change or not to change? Who special knows!?

Well said so much, drink a cup of water to smooth a line of thought, this is not accreditations, or the last code test:

#include <stdio.h> #include <time.h> #include <stdlib.h>//has three doors, one of which has prizes, three of which you select one of the doors. The moderator first not reveal the answer, but from another two doors to exclude a no prize door//Now the host asked you, or to change the door, would you like to change or not? 9//Test (total number of times, door changer) void Test (int max, int change);//Entry function void Main () {//the number of times each test was tested int count = 20;//Initialize random seed srand ((unsigned) time ( NULL);//non-change door test printf ("No change gate test: \ n"); Test (count, 0);//change-Gate testing printf ("door changer: \ n"); Test (count, 1);}        Test (total number of times, door change) void Test (int max, int changed) {//max times: Total number of tests//change door changer: 0 No 1 door changer int i;        Cyclic factor int m;        Objective: The target number of this jackpot is int c;        Primary: The number of the first choice of the player int x;        Selection: This contestant finally chooses the number int p;    Exclude: The moderator excludes the number of the prize not int z = 0; Jackpot: Total number of WINS//cycles multiple simulation Gate test for (i=0; i<max; i++) {m = rand ()%3;//target: The target number of this jackpot is C = rand ()%3;//Primary: The number of the first choice of the contestant//  Figure out the number if the host wants to exclude the IF (M==C) {//The contestant chooses a prize, and the host randomly excludes the other two from the prize. P = rand ()%2; Generates false or Trueswitch (c) {case 0://To exclude: 2 or 1p = P?2:1;break;case 1://To exclude: 2 or 0p = p?2:0;break;case 2://To exclude Yes: 1 or 0p = P?1:0;break;;}} else{//Player chooses a no prize, the host excludes the other//3-(m+c) = p//3-(0+1) = 2//3-(0+2) = 1//(1+2) = 0p = (m+c);  }//determines the final option if (change) {//Door changer//x=3-(p+c)//x=3-(0+1) = 2//x=3-(0+2) = 1//x=3-(1+2) = 0x = (p+c);  Change the door}else{//not change the door x = C; The final choice is the same as the initial selection}//results printf ("%02d primary is:%d, the target is:%d, excluding:%d, the final selection is:%d", i+1, C, M, p, X); if (m==x) {//won z++;p rintf ("(winning) \ n ");} else{//not winning printf ("\ n");}} The output results in printf ("%d tests, winning%d times.") \ n ", Max, z);}

In addition, when 1000 tests are required, it is not suitable for each test results are output, the code slightly changed, the C language code to everyone to see

#include <stdio.h> #include <time.h> #include <stdlib.h>//has three doors, one of which has prizes, three of which you select one of the doors. The moderator first not reveal the answer, but from another two doors to exclude a no prize door//Now the host asked you, or to change the door, would you like to change or not?    Test (total number of times, door change) void Test (int max, int changed);//ingress function void Main () {//The number of individual tests int I, count = 1000;    Initializes a random seed srand ((unsigned) time (NULL));        for (i=0;i<5;i++) {printf ("================================\n");        Do not change the door test printf ("Do not change the door test: \ n");        Test (count, 0);        Change door test printf ("door changer test: \ n");    Test (count, 1);        }}//Test (total number of times, door change) void Test (int max, int changed) {//max number of times: Total number of tests//change door changer: 0 No 1 door changer int i;        Cyclic factor int m;        Objective: The target number of this jackpot is int c;        Primary: The number of the first choice of the player int x;        Selection: This contestant finally chooses the number int p;    Exclude: The moderator excludes the number of the prize not int z = 0; Jackpot: Total number of WINS//cycles multiple simulation Gate test for (i=0; i<max; i++) {m = rand ()%3;//target: The target number of the winner C = rand ()%3;//Primary : The number of the first choice of the contestant//find the host to exclude the number if (m==c) {//players selected a prizeThe host is randomly excluded from the other two without prizes P = rand ()%2;                Generates false or True switch (c) {case 0://To exclude: 2 or 1 p = p?2:1;            Break                Case 1://To exclude: 2 or 0 p = p?2:0;            Break                Case 2://To exclude: 1 or 0 p = p?1:0;            break;;            }} else {//the player chooses a no prize, the host excludes another//3-(m+c) = P//3-(0+1) = 2                    0+2 = 1//3-(1+2) = 0 p = (m+c); }//Decide the final option if (change) {//Gate//x=3-(p+c)//x=3-(0+1) = 2//x=3-  (0+2) = 1//x=3-(1+2) = 0 x = (p+c);  Change the door} else {//Do not change doors x = C;        The final choice is the same as the initial selection}//Result//printf ("%02d primary is:%d, the target is:%d, excluding:%d, the final selection is:%d", i+1, C, M, p, X); if (m==x) {//winning z++;        printf ("(winning) \ n");        } else {//did not win//printf ("\ n"); }}//Output result printf ("tested%d times, winning%d times.") \ n ", Max, z);}

The conditional probability problem in a game

Related Article

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.