#P6708. [CCC 2020] Josh's Double Bacon Deluxe

    ID: 7417 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP2020Special JudgeCCC(加拿大)期望

[CCC 2020] Josh's Double Bacon Deluxe

Background

Josh and N1N-1 other people go to eat burgers.

Problem Description

This burger shop has MM types of burgers.

Person ii likes burger type bib_i the most.

All NN people will choose their favorite burger.

Now, these NN people line up to pick up burgers. Unfortunately, the first person forgets his favorite burger, so he takes a random burger.

The next N2N-2 people will take burgers according to the following rules:

  • If his favorite burger is available, he takes it directly.
  • Otherwise, he takes a random one.

You need to find the probability that Josh, who is last in line, gets his favorite burger.

Input Format

The first line contains an integer NN.

The next NN lines each contain an integer bib_i.

Output Format

Output one decimal number, representing the probability that Josh, who is last in line, gets his favorite burger.

3
1 2 3

0.5
7
1 2 3 1 1 2 3
0.57142857

Hint

Explanation for Sample 1

The first person's choice The second person's choice Josh's choice Probability
11 22 33 13\frac{1}{3}
22 11 13×12=16\frac{1}{3}\times \frac{1}{2}=\frac{1}{6}
33 11 16\frac{1}{6}
33 22 13\frac{1}{3}

The probability that Josh gets his favorite burger is 13+16=12\frac{1}{3}+\frac{1}{6}=\frac{1}{2}.

SPJ Scoring

Let the correct answer be CC, and your answer be PP. If PC<106\lvert P-C\rvert <10^{-6}, then you get full score for this test point; otherwise, you get 00.

Subtasks

This problem uses bundled tests, and the Subtask scores have been slightly adjusted.

  • Subtask 1 (2727 points): It is guaranteed that N105N\le 10^5, M103M\le 10^3.
  • Subtask 2 (3333 points): It is guaranteed that M103M\le 10^3.
  • Subtask 3 (4040 points): No special restrictions.

Constraints

For 100%100\% of the testdata, it is guaranteed that 3N1063\le N\le 10^6, 1biM5×1051\le b_i\le M\le 5\times 10^5.

Notes

This problem is translated from Canadian Computing Competition 2020 Senior T5 Josh's Double Bacon Deluxe.

Translated by ChatGPT 5