#P9443. Fitch Cheney Card Trick with Markings
Fitch Cheney Card Trick with Markings
Fitch Cheney Card Trick with Markings
The classic Fitch Cheney trick allows a magician to correctly identify a hidden card from a deck by having an assistant reveal the other cards in a specific order. Traditionally, with a deck of 52 cards and 5 cards drawn, clever use of the properties of cards (e.g. suits and a cyclic ordering of ranks) guarantees the magician can deduce the hidden card. However, if the deck is larger the trick may fail due to insufficient information in the ordering. To overcome this, you have pre-marked the backs of all n cards with one of m distinguishable methods. When k cards are drawn uniformly at random, the assistant selects one card to hide and arranges the remaining k-1 cards in a certain order. The hidden card’s back (which shows its pre‐assigned mark) tells the magician which subset of the deck it belongs to, and the order of the other cards serves as a signal to identify the card within that subset.
Assume that among the k drawn cards, the assistant is allowed to choose any card to hide. If the hidden card has a marking that appears on f cards in the deck, then the magician’s candidate set is exactly those f cards. With the ordering of the k-1 face-up cards, the assistant can send at most (k-1)! distinct signals. Thus, if it is possible to find a card in the hand with
[ (k-1)! \ge f, ]
then the trick can be performed with certainty. In a uniform marking of the deck, we have f = n/m for every card, so the trick is guaranteed to succeed if
[ m \times (k-1)! \ge n. ]
Otherwise, with optimal play the best success probability is
[ P = \frac{m \times (k-1)!}{n}, ]
given that the assistant uses the best possible strategy.
Your task is: given three integers n, k, and m, determine the maximum probability of the magician successfully guessing the hidden card, assuming optimal strategy. If m × (k-1)! ≥ n, output 1. Otherwise, output m × (k-1)! / n.
inputFormat
The input consists of a single line containing three integers n, k, and m:
- n (1 ≤ n ≤ 109) — the total number of playing cards.
- k (2 ≤ k ≤ 10) — the number of cards drawn.
- m (1 ≤ m ≤ 105) — the number of distinguishable marking methods.
It is guaranteed that the drawn cards are chosen uniformly at random from the deck.
outputFormat
Output the maximum probability of success. If the probability is less than 1, output it as a floating point number. Your answer is considered correct if its absolute or relative error does not exceed 10-6.
sample
52 5 4
1