No.352 Card Arrangement
タグ : / 解いたユーザー数 91
作問者 :
nmnmnmnmnmnmnm
Problem Statement
You are given N cards in total, one each with a number from 1 to N written on it.
First, A places card 1 at a cost of 1.
Then, A arranges the cards in a single horizontal row, in increasing order of their numbers.
When $M$ cards have already been placed,
there are $M+1$ ways to place the next card: "leftmost", "rightmost", or "inserted between any two cards",
and each is chosen uniformly at random with probability $\frac{1}{M+1}$.
The cost depends on how the card is placed.
・If it is placed at the leftmost or rightmost end of the existing row, the cost is 1.
・If it is inserted between two existing cards, the cost is the product of the numbers on the two cards adjacent to the placed card.
When A places the cards in order starting from card 1,
find the expected value of the total cost incurred until the last, N-th card has been placed.
Input
N
N is an integer. $2\le N \le 20$.
Output
Output the expected value on one line.
The allowed error is 1e-06.
Do not forget the newline at the end.
Sample
Sample 1
Input
2
Output
2.0000000000
Placing the first card, card 1, costs 1.
Next, placing card 2 costs 1 whether it is placed to the left or to the right of card 1.
Therefore, the expected cost of placing the two cards is 2.
Sample 2
Input
3
Output
3.3333333333
Placing the first card, card 1, costs 1.
Next, placing card 2 costs 1.
Next, when placing card 3, placing it at the leftmost position costs 1, with probability 1/3.
Placing it between cards 1 and 2 costs 2, which is $1\times2$, with probability 1/3.
Placing it at the rightmost position costs 1, with probability 1/3.
Therefore, from $1+1+(1+2+1)\times(1/3)$, the expected value is 3.33333333.
Sample 3
Input
17
Output
365.8791050453
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。