#P16770. [GKS 2020 #F] Yeetzhee

    ID: 19114 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP2020Special Judge期望Google Kick Start

[GKS 2020 #F] Yeetzhee

Problem Description

Pommel is very bored at home so she has invented a new game involving NN dice. Each die has the numbers from 11 to MM written on it. Whenever she throws a die, it has an equal probability of landing on each of the MM possible values.

Pommel places all the dice in a row. She goes through the dice one at a time from left to right. For each die she rolls, Pommel can either keep the value she rolled and move on to the next die or she can re-roll the die. Pommel can re-roll a die as much as she wants before moving on to the next die.

Once Pommel has gone through all the dice, the game is finished. To determine if she has won, she puts the dice into groups. All dice with the same value are put into the same group. So if she finishes the game with xx distinct values, then there will be xx groups. These groups of dice are then sorted by number of dice in non-decreasing order.

For example:

  • If the final dice results are [2,2,3,2,2,3][2, 2, 3, 2, 2, 3], the dice would be put into 22 groups and ordered as follows: [3,3][3, 3] and [2,2,2,2][2, 2, 2, 2].
  • If the final dice results are [1,6,7,7][1, 6, 7, 7], the dice would be put into 33 groups and ordered as follows: [6][6], [1][1], and [7,7][7, 7] (or equivalently, [1][1], [6][6] and [7,7][7, 7]).

Pommel wins if she finishes the game with exactly KK groups, and the ii-th group contains exactly AiA_i dice, for all ii.

What is the expected value of the total number of dice rolls it will take Pommel to win the game, assuming she plays optimally to minimize this expected value?

It is guaranteed that for any valid input, it is possible for Pommel to win the game.

Input Format

The first line of the input gives the number of test cases, TT. TT test cases follow. The first line of each test case contains the integers NN, MM, and KK. Then, KK lines follow describing the groups she must finish with. The ii-th line contains AiA_i.

Output Format

For each test case, output one line containing Case #xx: yy`, where xx is the test case number (starting from 11) and yy is the expected number of times it will take to roll all the dice for Pommel to win the game.

yy will be considered correct if it is within an absolute or relative error of 10610^{-6} of the correct answer.

2
3 6 2
1
2
5 2 1
5
Case #1: 4.7
Case #2: 9.0

Hint

In Sample case #11, Pommel has N=3N = 3 dice, each with a number from 11 to M=6M = 6 written on them. To win, she must finish the game with K=2K = 2 groups. One group must have 11 die (A1=1A_1 = 1), while the other group must have 22 dice (A2=2A_2 = 2). One optimal strategy for Pommel is as follows:

  • Pommel throws the first die 11 time.
  • Pommel throws the second die 11 time.
  • If the first and second dice are the same, Pommel keeps throwing the third die until it ends in a different value from the first two. It takes 1.21.2 dice rolls on average.
  • If the first and second dice are different, Pommel keeps throwing the third die until it matches the first or the second die. It takes 33 dice rolls on average.

This strategy takes Pommel 4.74.7 (1+1+1/6×1.2+5/6×31 + 1 + 1/6 \times 1.2 + 5/6 \times 3) dice rolls on average.

In Sample case #22, Pommel has N=5N = 5 dice, each with a number from 11 to M=2M = 2 written on them. To win, she must finish the game with K=1K = 1 group, with all NN dice in it (A1=NA_1 = N). For die 11, Pommel rolls it 11 time. Then, for each remaining die, she keeps rolling until it has the same value as die 11. It takes 22 dice rolls on average.

This strategy takes Pommel 99 (1+2+2+2+21 + 2 + 2 + 2 + 2) dice rolls on average.

Limits

1T1001 \le T \le 100.

1KM1 \le K \le M.

1Ai1 \le A_i, for all ii.

A1+A2+...+AK=NA_1 + A_2 + ... + A_K = N.

AiAi+1A_i \le A_{i+1}, for all ii.

Test Set 11

2N62 \le N \le 6.

2M62 \le M \le 6.

Test Set 22

2N502 \le N \le 50.

2M502 \le M \le 50.