Bob goes to a party, wearing a hat that fits him well. At the end of the party, Bob picks up a hat, without looking at it. He knows that the hat he has picked is his own with probability p. As a first check to see if he has picked up his own hat, he tries the hat, and if it fits, he decides that it is his own hat.

However, even if the hat picked by Bob is not his own, it is still possible that it fits with probability q. Given that Bob picked a hat that fits him, what is the probability that he is correct in deciding that the hat is indeed his own?