#P16029. [CSPro 23] 收集卡牌

    ID: 18035 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>2021Special JudgeO2优化期望状压 DPCSPro

[CSPro 23] 收集卡牌

Background

Luogu’s testdata is only for community communication and is not official testdata. Official judging link: https://www.cspro.org/.

Problem Description

Xiaolin is playing a gacha game. There are nn different types of cards, numbered from 11 to nn. Each draw gives her a type ii card with probability pip_i. If she has already obtained this card before, it will be converted into a coin. She can use kk coins to exchange for one card that she has not obtained yet.

Xiaolin will keep drawing until she has collected all types of cards. Find the expected number of draws. If the absolute error between your answer and the standard answer is at most 10−410^{-4}, it will be considered correct.

Hint: Smart Xiaolin will keep the coins, and when exchanging can obtain all remaining cards, she will exchange them all at once and stop drawing.

Input Format

Read from standard input.

There are two lines. The first line contains two positive integers n,kn, k separated by spaces. The second line gives p1,p2,…,pnp_1, p_2, \dots, p_n, separated by spaces.

Output Format

Write to standard output.

Output one line with a real number, the expected number of draws.

2 2
0.4 0.6
2.52
4 3
0.006 0.1 0.2 0.694
7.3229920752

Hint

Sample 1 Explanation

There are 22 types of cards. Let them be A and B, with probabilities 0.40.4 and 0.60.6. 22 coins can be exchanged for one card. The possible cases are:

  • The first draw gets A, the second draw gets B, then it ends. Probability 0.4×0.6=0.240.4 \times 0.6 = 0.24, number of draws 22.
  • The first draw gets A, the second draw gets A, the third draw gets B, then it ends. Probability 0.4×0.4×0.6=0.0960.4 \times 0.4 \times 0.6 = 0.096, number of draws 33.
  • The first draw gets A, the second draw gets A, the third draw gets A, exchange coins for B, then it ends. Probability 0.4×0.4×0.4=0.0640.4 \times 0.4 \times 0.4 = 0.064, number of draws 33.
  • The first draw gets B, the second draw gets A, then it ends. Probability 0.6×0.4=0.240.6 \times 0.4 = 0.24, number of draws 22.
  • The first draw gets B, the second draw gets B, the third draw gets A, then it ends. Probability 0.6×0.6×0.4=0.1440.6 \times 0.6 \times 0.4 = 0.144, number of draws 33.
  • The first draw gets B, the second draw gets B, the third draw gets B, exchange coins for A, then it ends. Probability 0.6×0.6×0.6=0.2160.6 \times 0.6 \times 0.6 = 0.216, number of draws 33.

So the answer is $0.24 \times 2 + 0.096 \times 3 + 0.064 \times 3 + 0.24 \times 2 + 0.144 \times 3 + 0.216 \times 3 = 2.52$.

Subtasks

For 20%20\% of the data, 1≤n,k≤51 \leq n, k \leq 5.

For another 20%20\% of the data, all pip_i are equal.

For 100%100\% of the data, 1≤n≤161 \leq n \leq 16, 1≤k≤51 \leq k \leq 5, all pip_i satisfy pi≥110000p_i \geq \frac{1}{10000}, and ∑i=1npi=1\sum_{i=1}^{n} p_i = 1.

Constraints

Translated by ChatGPT 5