CF1842G.Tenzing and Random Operations
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Yet another random problem.
Tenzing has an array a of length n and an integer v.
Tenzing will perform the following operation m times:
- Choose an integer i such that 1≤i≤n uniformly at random.
- For all j such that i≤j≤n, set aj:=aj+v.
Tenzing wants to know the expected value of ∏i=1nai after performing the m operations, modulo 109+7.
Formally, let M=109+7. It can be shown that the answer can be expressed as an irreducible fraction qp, where p and q are integers and q≡0(modM). Output the integer equal to p⋅q−1modM. In other words, output the integer x that 0≤x<M and x⋅q≡p(modM).
又一道随机问题。
丹增有一个长度为 n 的数组 a 和一个整数 v。
丹增将执行以下操作 m 次:
- 均匀随机选择一个整数 i,满足 1≤i≤n。
- 对所有满足 i≤j≤n 的 j,令 aj:=aj+v。
丹增想知道:执行 m 次操作后,∏i=1nai 的期望值(对 109+7 取模)。
形式化地,令 M=109+7。可以证明答案可表示为既约分数 qp,其中 p 和 q 为整数,且 q≡0(modM)。请输出整数 p⋅q−1modM。换言之,输出满足 0≤x<M 且 x⋅q≡p(modM) 的整数 x。
输入格式
The first line of input contains three integers n, m and v (1≤n≤5000, 1≤m,v≤109).
The second line of input contains n integers a1,a2,…,an (1≤ai≤109).
输入的第一行包含三个整数 n、m 和 v(1≤n≤5000,1≤m,v≤109)。
输入的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)。
输出格式
Output the expected value of ∏i=1nai modulo 109+7.
输出 ∏i=1nai 的期望值对 109+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 a after performing all the m operations :
1. a1=2,a2=12 with 41 probability.
2. a1=a2=12 with 41 probability.
3. a1=7,a2=12 with 21 probability.
So the expected value of a1⋅a2 is 41⋅(24+144)+21⋅84=84.
执行全部 m 次操作后,a 有以下三种情况:
- a1=2,a2=12,概率为 41;
- a1=a2=12,概率为 41;
- a1=7,a2=12,概率为 21。
因此,a1⋅a2 的期望值为
41⋅(24+144)+21⋅84=84.
输入解题思路,AI测评打分。不知道怎么写?