Jack and Jill
Time limit1sMemory limit64 MB
Given n couples seated in a circle, find the expected number of dance rounds before a female is paired again with a male she already danced with.
- Level
Medium7 of 10
- Topics
- Probability, Dynamic programming, Math
- Solved
- No attempts yet
문제
There are males and females who take part in a dance competition. The competition runs under these rules:
- At first, the males and females are randomly matched into couples, and all the couples are arranged in a circle.
- The judge flips a coin to choose , which is either or with equal probability. Then another coin flip chooses "clockwise" or "counter-clockwise", also with equal probability.
- Following the coin flips from the previous step, each female moves positions around the circle in the chosen direction and takes the partner she lands on. The males stay in place.
- If, after moving, a female is matched with a male she already danced with in an earlier round, the competition ends and the judges determine the winners. Otherwise, the current couples dance a round, the judges evaluate them, and the process returns to step 2.
Find the expected number of rounds danced during the competition.
입력
A single line containing an integer ().
출력
Print the answer with an accuracy of .