#P16639. [GKS 2018 #A] Lucky Dip

    ID: 19002 远端评测题 3000ms 1024MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP数学2018Special Judge期望Google Kick Start

[GKS 2018 #A] Lucky Dip

Problem Description

You are participating in the Grand Kickstart Lucky Dip with many fantastic and amazing prizes (and some not so good ones)!

In this Lucky Dip, there is a bag with NN items. The ii-th item in the bag has value ViV_i. You will put your hand into the bag and draw one item at random; all items in the bag have an equal probability of being chosen. The organizers want contestants to feel that they have some element of choice, so after you draw an item, you can either keep it, or "redip" by returning it to the bag and drawing again. (Note that the returned item is now just as likely to be chosen as any of the other items in the bag.) You may only redip a maximum of KK times. If you use KK redips, you must keep the item that you draw on your (K+1)(K + 1)-th draw.

If you play optimally to maximize the value of the item you will end the game with, what is the expected value of that item?

Input Format

The input starts with one line containing one integer TT: the number of test cases. TT test cases follow.

Each test case consists of two lines. The first line consists of two integers NN and KK: the number of items in the bag, and the maximum number of times you may redip. The second line consists of NN integers ViV_i, each representing the value of the ii-th item.

Output Format

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 11) and yy is the expected value described above. Your answer will be considered correct if it is within an absolute or relative error of 10610^{-6} of the correct answer.

5
4 0
1 2 3 4
3 1
1 10 1
3 15
80000 80000 80000
1 1
10
5 3
16 11 7 4 1
Case #1: 2.500000
Case #2: 6.000000
Case #3: 80000.000000
Case #4: 10.000000
Case #5: 12.358400

Hint

In Sample Case #1, you cannot redip, so the expected value is just the mean of the items in the bag which is (1+2+3+4)/4=2.5(1 + 2 + 3 + 4) / 4 = 2.5.

In Sample Case #2, the best strategy is to keep the item of value 1010 if you get it, and redip otherwise. The chance of getting that item (on either the first or second draw) is 1(2/3)2=5/91 - (2/3)^2 = 5/9, hence the expected value is (5/9×10)+(4/9×1)=6(5/9 \times 10) + (4/9 \times 1) = 6.

In Sample Case #3, since all the items have the same value, it does not matter how many times you redip and hence the expected value is 8000080000.

Note that cases #3 and #5 would not appear in the Small dataset.

Limits

1T1001 \le T \le 100.

1Vi1091 \le V_i \le 10^9.

1N2×1041 \le N \le 2 \times 10^4.

Small dataset (Test set 1 - Visible)

0K10 \le K \le 1.

Large dataset (Test set 2 - Hidden)

0K5×1040 \le K \le 5 \times 10^4.