Original post problems:
100 people lined up to take a plane with 100 seats. Normally, each person would sit at the opposite number. However, the first person on the plane was a dumb and he sat in a random seat, when people are on the plane, if they are seated, they will randomly find a seat to sit down. Otherwise, they will sit down. Q: What is the probability that the last person on the plane will sit in his seat ??
My answer:
1. Set F (n) to indicate the probability that the last person (n) can sit in his position when there is a fool and n-1 person.
2. since a fool is sitting at random, when he is sitting at the position of 2nd people, 2nd people can only sit at random in other positions because they cannot sit at their own positions, he can be regarded as 2nd "Dummies ".
So in addition to 1st dummies, n-1 individual can be seen as "a dummies (that is, 2nd people can not find the location) and the remaining N-2 individual ", in this case, the probability that the last person can sit at his position is F (n-1). Therefore, if the first fool is sitting at the position of 3rd people, 2nd people will directly sit at his position, in this case, the probability that the last person can sit in his position is F (n-2 ).....
If the first fool is sitting in n-1 position, the n-1 person becomes a "fool". The probability that the last person can sit in his position is F (2) = 0.5; at last, if a fool is sitting in a position other than n-1, then the probability that the last person can sit in his position is 1. because a fool is sitting at random, the probability of sitting at each person is 1/N.
So in general, the probability that the last person (NTH) can sit at his position:
F (n) = f (n-1) * (1/n) + f (n-2) * (1/n) +... + F (2) * (1/n) + 1 * (1/n );
That is, F (n) = (1/n) * (f (n-1) + f (n-2) +... + F (2) + 1 );
The Code is as follows:
Public double F (int n)
{
Double S = 0;
If (n = 2)
{
Return 0.5;
}
Else
{
For (INT I = 2; I <n; I ++)
{
S + = f (I );
}
Return (S + 1)/(double) (n );
}
}
However, I 'd like to remind you that the above Code uses multiple recursion, so the efficiency is very low. When n = 100, it will not be completed in a few minutes, but all N = 2 ~ The result of all numbers in 30 is 0.5.
So 0.5 is the standard answer!
Answers from other people on the Internet:
My answer is 1/2
First give a formula
F (n) = 1/n + (1/n) [F (n-1) + f (n-2) +... + F (2)]
F (2) = 1/2
Obtained F (n) = 1/2
Explain the above formula:
Starting from dummies, from 100 to 1
Place the nth person in the seat number of the nth person
Call seat 100th a "dedicated seat for Dummies"
A fool has a 1/100 probability to choose "a dedicated seat for a fool" (No. 100th)
Then the first person must be able to sit in the 1st seat.
Dummies have a 1/100 probability of choosing other seats (assuming the k Number)
From 99th to the K + 1, you will all be seated in your own seat.
When selecting the K, the k-th seat was already seated
We can treat him as a "dumb"
With a probability of 1/K, select "dedicated seat for Dummies" (100th)
With a probability of 1/K, choose seat 1st to K-1.
Based on this idea
If F (n) is the probability that guests on the N th will be able to sit in the 1st th seat when there are n seats that do not have seats on the N th seat
F (100) is the probability that a fool will be able to sit in 100 seats when facing 1st seats.
Obviously
F (2) = 1/2
F (n) = 1/n + (1/n) f (n-1) + (1/n) f (n-2) + (1/n) f (n-3) +... ++ (1/n) f (3) + (1/n) F (2)
There is only one dumb. People who are not in the position will not sit in disorder until the person in the position gets on the plane and then sit in another place. So one of the people without a plane is occupied. If a person who is in a position sits in the dummies, then he will not occupy the latter's position, and the latter will not sit in disorder. Check whether the dummies are occupied.
If X is set to N, the dummies are not occupied. If y is set to n + 1, the dummies are not occupied,
If X is not true, the n-th person will be taken up after the n-th person sits down, and Y will not happen, and the n-th person will definitely sit in his position.
P (y) = P (Y, X)
The occurrence of X indicates that there is only one person's seat in the back of N.
Y is discussed in two cases,
First, the seat of the n + 1 person is occupied, and the probability of occurrence of X is 1/(-N), (including him,-N people did not sit down, one of them is occupied ). The probability of sitting in the dummies is 1/(-N). (in this case, there are-N vacancies, and one is randomly selected ). Y occurs because he is not a dumb. Probability: 1/(100-n) * (1-1/(100-n ))
Second: the seats of N + 1 persons are not occupied. The probability of occurrence of X is (100-n-1)/(100-n)
P (Y | X) = 1/(100-n) * (1-1/(100-n) + (100-n-1)/(100-n)
= {(100-n-1)/(100-n)} * {(100-n + 1)/(100-n )}
P (y) = P (Y, x) = P (Y | x) * p (x)
The probability that n + 1 people sit down and have no such positions
P (n + 1) = {(100-n-1)/(100-n)} * {(100-n + 1)/(100-n )} * P (n)
= {(100-n-1)/(100-n)} * {(100-n + 1)/(100-n )}*
{(100-(N-1)-1)/(100-(N-1)} * {(100-(N-1) + 1) // (100-(N-1)} * P (n-1)
= {(100-n-1)/(100-n)} * {(100-n + 2)/(100-n + 1)} * P (n-1)
=...
= {(100-n-1)/(100-n)} * {(100-J + 1)/(100-j)} * P (j)
=...
= {(100-n-1)/(100-n)} * {(100-1 + 1)/(100-1)} * P (1)
= {(100-n-1)/(100-n)} * 100/99 * P (1)
P (1) is the probability that a fool is not occupied after sitting down.
P (1) = 99/100,
P (n + 1) = (100-n-1)/(100-N)
P (n) = (100-N)/(101-N)
The probability that 99th people sit down and are not occupied by fools
P (99) = 1/2
So the probability of the last person sitting in his position = 1-P (99) = 0.5
Assume that p is a fully arranged n that meets the requirements of the question. For example, 1234 indicates that the first person is in the No. 1 position, and so on, all the sorting sets meeting The question requirements are {p };
* 1. When the k-th person got on the plane, he could not be numbered 2 to the seat of the K-1.
Proof: If he can sit in the I seat (2 <= I <= k-1), it means that when I got on the plane, the I seat is empty, then he should sit in the I-th seat, and the k-th individual cannot sit in the I-th seat.
Conclusion 1: When the n-th person is on the plane, he can only sit on the 1 or n-th.
2. P1 and P2 are used to represent the nth person. If PI occupies PJ's seat, the directed edge pi-> PJ is used to form the directed graph G.
2-1; the degree of any vertex in G: the inbound and outbound degrees are 1 or 0
* 2-2: a maximum of one connected branch (G') exists in G. It contains two or more vertices and P1 belongs to G'
2-3: From the above two points, we can see that if G' exists, it constitutes a one-way connected loop chain. If it does not exist, we will add the definition that G' only contains P1.
3. Define an incorrect sorting column S in P to meet the following requirements:
(1) The first element is in the sequence header, and 1 ends in the sequence.
(2) Except 1, other elements in the sequence are monotonically added.
(3) P does not have a sequence that satisfies the definition longer than S.
Example: P = 1234, S = 1;
P = 2134, S = 21
P = 3214, S = 31
P = 2314, S = 231
P = 2341, S = 2341
It is easy to see. The actual meaning of S is that a "loop occupies the chain" of people who are not sitting in their seats. In the 2314 arrangement, S = 231, it means that 1st people occupy seats 1 and 2, 2nd people occupy the third seat, and the third person occupies the 1 seat. That is, the one-way loop chain G' defined in 2'
4. There is a one-to-one correspondence between P and S.
P-> the only S, which has been proved in 2, s-> P. Obviously, because N is not a number in S, it must be in its original position, this arrangement is of course unique.
5. From S to P, the method has been described in 4
Example N = 4:
S = {3, 1}, {n}-S = {2, 4}, insert 2 to the second position, and then insert 4 to the fourth position.
S = {2, 3, 4, 1}, {n}-S = empty set, so s itself is P
* 6. inference: Assume that the number k Represents the seat number 1, and the largest seat number prior to him is Q. Then, start from the number q + 1 and start from the seat number. (Strong conclusion)
7. Number of S and P
From the generation of S, s can be 2 to n of a full group merge on {1}, by the two theorem, we can know that for N, the total number of satisfied arrangement is 2 ^ (N-1)
* 8. Define a concatenation of S as '= {x | x = 1 or X does not belong to n}
S = {1}. s' = {2, 3, 4, 1}
S = {2, 1 |, s' = {3, 4, 1}
S = {3, 1}, s' = {2, 4, 1}
For {s} to do a Division, the Division is based on whether it contains 4 (n), because s does not exist in the Self-affinity, the two parts of the elements are equal, the same as 2 ^ (N-2)
9. Proof: when the last person got on the plane, he sat in his own position and only when the p-sorted generation s does not contain {n}
Adequacy: If s does not contain N, the maximum number of Q in S <N-1. according to inference 6, when n> = k> = q + 1, the last person must sit in his seat.
Necessity: according to the definition of S.
10. Conclusion 8 and Conclusion 9 show that the answer to this question is 1/2.