Under construction

Still being built. Things may change

Flipping Coins

Interview

Time limit2sMemory limit512 MB

Summary
Each step flips a uniformly random set of A_i coins; find the expected number of heads after all K steps.
Level

Medium6 of 10

Topics
Probability, Dynamic programming, Combinatorics
Solved
No attempts yet

Problem

There are NN coins on a table. Every coin starts heads up.

You are given KK integers A1,A2,…,AKA_1, A_2, \dots, A_K. In the first step you choose A1A_1 coins at random and flip them, in the second step you choose A2A_2 coins at random and flip them, and you repeat this until the KK-th step. Each step picks one of the sets of size AiA_i uniformly at random, independently of what the earlier steps did.

Compute the expected number of coins that are heads up after all steps are done.

Input

The first line contains the number of coins NN (1≤N≤10001 \le N \le 1000).

The second line contains the number of steps KK (1≤K≤501 \le K \le 50).

The third line contains A1,A2,…,AKA_1, A_2, \dots, A_K (1≤Ai≤N1 \le A_i \le N), separated by spaces.

Output

Print, on one line, the expected number of coins that are heads up after all steps are done.

Round the value at the eleventh digit after the decimal point so that exactly 10 digits follow the decimal point. Round a half up. Pad with zeros when the value is an integer, so an expected value of 00 prints as 0.0000000000.

Hint

Take N=3N = 3 and A=(2,2)A = (2, 2). The first step flips 2 coins, which leaves 1 head and 2 tails. The second step has two possible outcomes.

  • It picks the 2 tails and flips them. The probability is 1/31/3 and the number of heads becomes 3.
  • It picks 1 head and 1 tail and flips them. The probability is 2/32/3 and the number of heads becomes 1.

The expected value is 13×3+23×1=53\frac{1}{3} \times 3 + \frac{2}{3} \times 1 = \frac{5}{3}.

Examples3

  1. Example 1

    Input
    3
    2
    2 2
    
    Expected output
    1.6666666667
    
  2. Example 2

    Input
    10
    3
    10 10 10
    
    Expected output
    0.0000000000
    
  3. Example 3

    Input
    10
    6
    2 7 1 8 2 8
    
    Expected output
    4.7926400000