問題一覧 > 通常問題

No.1904 Never giving up!

レベル : / AI推定難易度 : 500 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 178
作問者 : 👑 hitonanode / テスター : Sumitacchan
お気に入りにしたユーザー ProblemId : 6232 / 自分の提出
問題文最終更新日: 2022-04-26 01:19:21
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 339 (順位表) の他の問題:

Problem Statement

A bag whose contents cannot be seen contains $N$ balls. Each ball has one integer written on it, and the integer written on the $i$-th ball ($1 \le i \le N$) is $A_i$.

You take on a game in which you draw the $N$ balls from the bag one at a time. You win if the integers written on the drawn balls are monotonically non-decreasing (that is, letting $B_t$ be the integer written on the ball drawn $t$-th $(1 \le t \le N)$, $B_t \le B_{t + 1}$ holds for all $t = 1, \dots, N - 1$). Conversely, if at any point in the game you draw a ball with a smaller number than the ball drawn immediately before it, you return all the balls to the bag, mix the contents well, and attempt the game again from the beginning. The balls are uniform in shape, and when a ball is drawn from the bag, every ball is equally likely to be chosen.

Find the expected number of attempts needed until you win this game once. It can be proved from the constraints of this problem that the answer is an integer less than $4 \times 10^{18}$.

Input

$N$
$A_1\ A_2\ \dots \ A_N$

  • $2 \le N \le 20$
  • $1 \le A_i \le N \, (1 \le i \le N)$
  • All inputs are integers.

Output

Output the integer that is the answer, followed by a newline.

Sample

Sample 1
Input
2
2 1
Output
2

The balls are drawn from the bag as either $[1, 2]$ or $[2, 1]$, each with probability $1/2$, and you win once you draw $[1, 2]$. The probability of winning for the first time on attempt $1$ is $1/2$, on attempt $2$ is $(1/2)^2$, on attempt $3$ is $(1/2)^3$, ..., so the expected value is $2$ attempts.

Sample 2
Input
5
5 2 2 2 2
Output
5

You only need to draw the ball with $5$ written on it last, so the probability of winning for the first time on attempt $1$ is $1 / 5$. The expected number of attempts until the first win can be calculated to be $5$.

Sample 3
Input
20
10 9 8 7 6 5 4 3 1 2 12 11 13 14 16 15 18 17 20 19
Output
2432902008176640000

Even making one attempt per second, the expected time until you win once is about $771$ hundred million years.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。