Under construction

Still being built. Things may change

Jack and Jill

Time limit1sMemory limit64 MB

Summary
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 nn males and nn females who take part in a dance competition. The competition runs under these rules:

  1. At first, the males and females are randomly matched into nn couples, and all the couples are arranged in a circle.
  2. The judge flips a coin to choose kk, which is either 11 or 22 with equal probability. Then another coin flip chooses "clockwise" or "counter-clockwise", also with equal probability.
  3. Following the coin flips from the previous step, each female moves kk positions around the circle in the chosen direction and takes the partner she lands on. The males stay in place.
  4. 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 nn (2≤n≤502 \le n \le 50).

출력

Print the answer with an accuracy of 10−910^{-9}.

Examples2

  1. Example 1

    Input
    3
    
    Expected output
    2.50000000000000000000
    
  2. Example 2

    Input
    5
    
    Expected output
    3.21875000000000000000