問題一覧 > 通常問題

No.352 Card Arrangement

レベル : / AI推定難易度 : 1300 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 小数誤差許容問題 絶対誤差または相対誤差が $10^{-6}$ 以下。ただし、ジャッジ側の都合で500桁未満にしてください
タグ : (AC するまで非表示) / 解いたユーザー数 91
作問者 : nmnmnmnmnmnmnm
お気に入りにしたユーザー ProblemId : 750 / 自分の提出
問題文最終更新日: 2026-06-30 04:08:24
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 133 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。