CF1842G.Tenzing and Random Operations

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Yet another random problem.

Tenzing has an array aa of length nn and an integer vv .

Tenzing will perform the following operation mm times:

  1. Choose an integer ii such that 1in1 \leq i \leq n uniformly at random.
  2. For all jj such that ijni \leq j \leq n , set aj:=aj+va_j := a_j + v .

Tenzing wants to know the expected value of i=1nai\prod_{i=1}^n a_i after performing the mm operations, modulo 109+710^9+7 .

Formally, let M=109+7M = 10^9+7 . It can be shown that the answer can be expressed as an irreducible fraction pq\frac{p}{q} , where pp and qq are integers and q≢0(modM)q \not \equiv 0 \pmod{M} . Output the integer equal to pq1modMp \cdot q^{-1} \bmod M . In other words, output the integer xx that 0x<M0 \le x < M and xqp(modM)x \cdot q \equiv p \pmod{M} .

输入格式

The first line of input contains three integers nn , mm and vv ( 1n50001\leq n\leq 5000 , 1m,v1091\leq m,v\leq 10^9 ).

The second line of input contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n ( 1ai1091\leq a_i\leq 10^9 ).

输出格式

Output the expected value of i=1nai\prod_{i=1}^n a_i modulo 109+710^9+7 .

输入输出样例

  • 输入#1

    2 2 5
    2 2

    输出#1

    84
  • 输入#2

    5 7 9
    9 9 8 2 4

    输出#2

    975544726

说明/提示

There are three types of aa after performing all the mm operations :

1. a1=2,a2=12a_1=2,a_2=12 with 14\frac{1}{4} probability.

2. a1=a2=12a_1=a_2=12 with 14\frac{1}{4} probability.

3. a1=7,a2=12a_1=7,a_2=12 with 12\frac{1}{2} probability.

So the expected value of a1a2a_1\cdot a_2 is 14(24+144)+1284=84\frac{1}{4}\cdot (24+144) + \frac{1}{2}\cdot 84=84 .

首页