Content

Tuesday, December 3, 2019

Probability and Expected Value (Light OJ)

Problem 1: 1027 - A Dangerous Maze 

Say, Total number of door is N.
So, probability of choosing any door is, P = 1 / N .
Total number of door which bring you back to the beginning is  N'
For getting out with the positive expected time is, Ex = Xi .
For getting out with the negative expected time is, Ey = abs(Xi) + E .
'E' means we have to start again!
 So, E = ( ∑Ex + ∑Ey ) / N
 => N *  E = ( abs(Xi) + N' * E) [As Positive number of door + N' = N, so we add Xi to N]
 => E = ( ∑abs(Xi) ) / (N - N')




Problem 2: 1030 - Discovering Gold 

Possibility of going to 1st position is T1 = 1.
Possibility of going to 2nd position is T2 = T1 / min(n - position from it comes, 6)
Possibility of going to 3rd position is T3 = (T1/min(n - position from it comes, 6)) + (T2/min(n - position from it comes, 6))
...
Possibility of going to nth position is Tn = (Ti-6/min(n - position from it comes, 6)) + (Ti-5/min(n - position from it comes,6)) + ... + (Tn/min( n - position from it comes, 6))

Now just add up the result, E =  ∑ Ti * ai




Problem 3: 1038 - Race to 1 Again 

Let, Expected value of n for the problem is E(n).
So, E(1) = 0
      E(2) = ( (E(1) + 1) / cnt) + ( (E(2) + 1) / cnt) [i.e. Here cnt = 2 as it has two divisors]
      ....
      E(n) = ( (E(1) + 1) / cnt) + ( (E(d1) + 1) / cnt) + ... + ( (E(n/d1) + 1) / cnt) + ( (E(n) + 1) / cnt) [i.e. Here d1 is a divisor of n]
 So, after solving the above equation we get, E(n) =  ( ∑ ( E(dt) + 1 ) ) / ( cnt - 1 ) [i.e. Here dt is 't'th divisor of n and cnt is total number of divisors of n]
 



Problem 4: 1079 - Just another Robbery 

Using the concept of 0-1 Knapsack DP we can easily do this problem. We will store minimum probability to get arrested to rob a bank and then we will check with given probability.
DP[total_money + Money[i]] = min( DP[total_money + Money[i]], DP[total_money] + (1 - DP[total_money]) * P[i] )




Problem 5: 1104 - Birthday Paradox 

Bithday Paradox , read this and you will get the answer. Here I have used the generalized formula.





Some Useful Links:
Sums and Expected Value — part 1 (by Errichto) 
Sums and Expected Value — part 2 (by Errichto) 
Explaination of LOJ 1027 

No comments:

Post a Comment