#P5645. Guaranteed Spring in Dou Di Zhu
Guaranteed Spring in Dou Di Zhu
Guaranteed Spring in Dou Di Zhu
In the card game Dou Di Zhu (Fight the Landlord) three players compete against one another. The landlord wins only if he achieves a "spring" victory – that is, if under optimal play his win is achieved without the farmers managing any counter‐play. Otherwise, even if the landlord plays out all his cards first, the win is counted for the farmers.
In this problem you are given n (with \(0 \le n \le 20\)) predetermined cards that must appear in the landlord’s initial hand. (The deck contains 54 cards numbered 1 through 54; by convention the two jokers are numbered 53 and 54.) The landlord’s hand always consists of exactly 20 cards. It turns out that under optimal play the landlord can force a spring win regardless of how the farmers’ cards are distributed if and only if his hand contains both jokers.
Your task is to count the number of 20‐card hands (taken from the 54‐card deck) that contain all of the given n cards and, in order to guarantee a spring win, also contain both joker cards (53 and 54). In other words, if the given set already has zero, one or both jokers, your hand must complete the set so that both 53 and 54 are present.
Note: It is possible that the predetermined cards already include one or both jokers. If the predetermined cards do not provide all of the two jokers then your chosen additional cards must include the missing joker(s).
Hint: Let \(c\) be the count of jokers present in the predetermined set. In order for a hand to guarantee a spring win it must include a total of 2 jokers. Thus, if \(r = 2 - c\) is the number of joker cards missing, then among the remaining \(20 - n\) cards you must choose these \(r\) jokers and any other \(20 - n - r\) cards from the rest of the deck (which has \(54 - n - r\) cards available). The answer is therefore:
[ \text{Answer} = \begin{cases} 0, & \text{if } 20 - n < 2 - c,\[1mm] \binom{54 - n - (2-c)}{20 - n - (2-c)}, & \text{otherwise.} \end{cases} ]
inputFormat
The first line contains a single integer n (\(0 \le n \le 20\)), the number of predetermined cards.
If n \(> 0\), the second line contains n distinct space‐separated integers between 1 and 54 indicating the predetermined cards (the two jokers are represented by 53 and 54).
outputFormat
Output a single integer – the number of possible 20-card initial hands that include the given predetermined cards and (necessarily) both jokers, so that the landlord is guaranteed to win by spring regardless how the other cards are distributed.
sample
0
4923689695575