dp: Probability and Expectation

If the probability of an event occurring is P, then the expectation is 1/P.

Topic link: https://vjudge.net/contest/222921

Password: ECJTUACM

 

A:

There are several portals, and you will randomly choose one of them. The portal with a value of a will let you leave in a minutes, and the portal with a value of -a will let you return to the starting point after a minutes. Find the one that left. expected time.

If the number of portals that can be left is a1, the number of portals that cannot be left is b1.

The probability of teleporting away is a1/( a1+b1).

Then the expected number of transfers to leave is ( a1+b1) /a1 times.

Find the average duration of each transmission and multiply it by the expected number of transmissions.

The question requires the output of the simplest fraction, which can be processed with gcd.

 

 

B:

There are gold mines numbered 1 to n, you are now at number 1 and you can mine the gold in your gold mine.

You roll a six-sided die to determine the number of steps you move, and reroll if the result of the die exceeds n.

Find the expectation of the total amount of gold mined.

The expected value of a gold mine will depend on the average expectation of the next gold mine to reach:

a[i]+=1/6*a[i+1]+ 1/6*a[i+2]+……+1/6*a[i+6]

So deal with it from big to small.

If the upper limit exceeds n, a corresponding adjustment is made.

 

Why push from the back to the front is explained as follows:

Let's take a counter example:

If we let the equation be

a[i]+=1/6*a[i-1]+ 1/6*a[i-2]+……+1/6*a[i-6]

a[2]=a[1]+a[2]

a[3]=0.5a[1]+0.5a[2]+a[3]=a[1]+0.5a[2]+a[3]

So

a[4]=1/3a[1]+1/3a[2]+1/3a[3]+a[4]=a[1]+0.5a[2]+1/3a[3]+a[4]

However, in fact a[4] expects this is not the case.

if 1 to 4

Starting at 1, the probability of going to 2 is 1/3, and the probability of going to 3 is 1/3 plus the probability of 2 to 3, which is 0.5.

So the correct one is a[4]=a[1]+1/3a[2]+0.5a[3]+a[4], which contradicts the forward push.

Why is pushing wrong? Seeing a[2] here, a[2] thinks that a[1] can only reach a[2]. From the perspective of a[2], the source of a[2] is only a[1], which is That's right, but the state transition equation also thinks that a[1] can only go to a[2]; a[3] thinks that a[1], a[2] can only go to a[3], resulting in an after-effect sex, this is a fatal logical error.

 

Why is a[i] to a[i+1]—a[i+6] right?

Because the logic is complete, there is no aftereffect.

Because the probability that a[i] diverges to the last six positions is the probability of throwing a dice to throw a certain number.

And the first six positions converge to one position, which is to throw six dice, the first throws 6, the second throws 5... The probability of the sixth throwing 1 seems to be 1 every time /6, but each state is actually irrelevant, and the so-called forward push transition equation is just a pseudo-proposition that looks right.

 

 

C:

A number is randomly divided by any of its factors until the result is 1, the desired number of divisions to be required.

Different from the above question, the expectation of a number dividing by 1 depends on the expectation of the number smaller than it, so deal with it from small to large.

a[i]=(a[1]+1+a[x2]+1+a[x3]+1+...+a[xn]+1+a[i]+1)/(number of factors )

Note that the factor includes 1 and itself and cannot be ignored.

Since the subject data is large, all the results must be preprocessed.

And the handling takes a little trick to save time.

 

 

D:

01 Expectation version of the backpack

The robber wants to rob the bank, and he doesn't want to get the most money if the probability of being arrested exceeds p.

Each bank has money and an arrest probability pi.

Probability method:

P=1-(1-p1)*(1-p2)*(1-p3)*……*(1-pn)

Then multiply to calculate the probability of not being arrested, and subtract to get the probability of being arrested.

 

 

E:

Roll an n-sided die and find the expected number of times each side appears once to be rolled.

If there are m faces that have not appeared, the probability of throwing the unappeared face is m/n.

Then the expected number of occurrences of a face that has not appeared before is n/m.

Let m be 1 to n and then sum the expectations.

 

 

F:

In a three-dimensional space, the lights that are turned off are evenly distributed, randomly select k times, select two points at a time, press the switches of all the lights in the two points once, and ask the expected number of lights that are turned on at the end.

 

That is, find the expected number of lights whose switches are pressed an odd number of times.

For a point with coordinates ( x,y,z),

Its probability of being selected on the x-axis is (n*n-(x-1)*(x-1)-(nx)*(nx))/n*n

The probability p that each position is pressed is obtained from the sub-triple loop .

For p, we ask for the probability that the position changes an odd number of times.

After f[i] is i times, the position is dark, and g[i] is i times, the position is bright

f[i]=(1-p)*f[i-1]+p*g[i-1]

gi]=(1-p)*g[i-1]+p*f[i-1]

Known boundary f[0]=1, g[0]=0

We can calculate g[k], which can be calculated directly with the matrix.

Of course, it can also be deduced, and the deduced result is

ans+=0.5*(1-pow(1-2*p,1.0*k));

 

 

G:

The longest path in the expected version can be solved by Dijkstra or Floyd

 

 

H:

You are blind, there are two kinds of sticks, one can be thrown after taking it, and the other can't.

Each stick has a weight, you are required to hold all the sticks, and the expected sum of the weights you have held is required.

A thrown stick is only taken once, so the expected contribution is 1*weight.

The stick that cannot be thrown is similar to the previous n-sided dice. We can easily know the probability and expected number of times of taking out a stick that has not been touched before, and then multiply it by the weight.

 

 

I:

The probability that you can't catch the next ball is p. If it ends when the k1 ball or the empty k2 ball is connected, find the expected number of servings

Let f[i] be the expected number of times to serve when the i ball is connected, and g[i] to be the expected number of times to serve when the i ball is connected.

f[i]= (1-p) *(f[i+ 1]+1)+ p *(g[1]+1)=(1-p)*f[i+1]+p*g[1]+1

It means that the probability of (1-p) is received , at this time the expectation is f[i+1] plus this ball, so +1, the probability of p is empty, then it is equivalent to the expectation of 1 empty ball plus this ball, so +1.

g[i]= p *(g[i+ 1]+1)+ (1-p) *(f[1]+1) =p*g[i+1]+(1-p)*f[1]+1

Boundary f[k1]=0, g[k2]=0

Let q=1-p

It can be deduced that f[1]=(1-q^(k1-1))*(p*g[1]+1)/(1-q)

g[1]=(1-p^(k2-1))*(q*f[1]+1)/(1-p)

The answer is f[0] or g[0]

 

 

J:

No, blah blah blah.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325339320&siteId=291194637