A and B play ping pong game multiple times. The person serving first has a probability p of winning that game. A serves the first game and thereafter the loser serves first. What is the Probability that A wins the nth game?
double p;
double f(int n)
{
if(n==1)
return p;
else
{
double d = f(n-1);
return d*(1-p)+(1-d)*p;
}
}
where the d is the prob. of A win the (n-1)th game, so d*(1-p) means if A wins n-1 th game, what is the prob. for A wins nth game, (1-d)*p means if A loses n-1th game, what is the prob. for A wins nth game.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment