Expected score

4.6

9 votes
Mathematics, Medium, Probablity, Basic Probability, Probability
Problem

Let's define the score of sequence A of length M the maximal number T such that there exist a sequence B  of length T with 1=B1<B2<<BTM and Bi is the smallest index bigger than Bi1 with ABi1ABi.

A sequence S of length N is randomly generated in the following way:

For each index i we assign V (1VK) to Si with probability pV.

Find the expected score of S modulo 109+7.

Input

The first line contains two integers - N,K(1N109,1K75).

The next line contains K nonegative integers - q1,q2,,qk, pi=qiq1+q2++qk (1q1+q2++qk109).

Output

It can be proved that the answer can be represented as a fraction PQ with Q0 and (P,Q)=1. Output the reminder of PQ1 when divided by 109+7.

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Consider the following sequences:

1. (1,1,1) appears with probability 127 and has score 3

2. (1,1,2) appears with probability 227 and has score 3

3. (1,2,1) appears with probability 227 and has score 2

4. (1,2,2) appears with probability 427 and has score 3

5. (2,1,1) appears with probability 227 and has score 1

6. (2,1,2) appears with probability 427 and has score 2

7. (2,2,1) appears with probability 427 and has score 2

8. (2,2,2) appears with probability 827 and has score 3

Editor Image

?