No.1904 Never giving up!
タグ : / 解いたユーザー数 178
作問者 : 👑
hitonanode
/ テスター :
Sumitacchan
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もしくは右上の雲マークをクリックしてアカウントを作成してください。