A16017 | Tenzing and Random Operations
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Yet another random problem.
Tenzing has an array $a$ of length $n$ and an integer $v$ .
Tenzing will perform the following operation $m$ times:
1. Choose an integer $i$ such that $1 \leq i \leq n$ uniformly at random.
2. For all $j$ such that $i \leq j \leq n$ , set $a_j := a_j + v$ .
Tenzing wants to know the expected value of $\prod_{i=1}^n a_i$ after performing the $m$ operations, modulo $10^9+7$ .
Formally, let $M = 10^9+7$ . It can be shown that the answer can be expressed as an irreducible fraction $\frac{p}{q}$ , where $p$ and $q$ are integers and $q \not \equiv 0 \pmod{M}$ . Output the integer equal to $p \cdot q^{-1} \bmod M$ . In other words, output the integer $x$ that $0 \le x < M$ and $x \cdot q \equiv p \pmod{M}$ .
Tenzing has an array $a$ of length $n$ and an integer $v$ .
Tenzing will perform the following operation $m$ times:
1. Choose an integer $i$ such that $1 \leq i \leq n$ uniformly at random.
2. For all $j$ such that $i \leq j \leq n$ , set $a_j := a_j + v$ .
Tenzing wants to know the expected value of $\prod_{i=1}^n a_i$ after performing the $m$ operations, modulo $10^9+7$ .
Formally, let $M = 10^9+7$ . It can be shown that the answer can be expressed as an irreducible fraction $\frac{p}{q}$ , where $p$ and $q$ are integers and $q \not \equiv 0 \pmod{M}$ . Output the integer equal to $p \cdot q^{-1} \bmod M$ . In other words, output the integer $x$ that $0 \le x < M$ and $x \cdot q \equiv p \pmod{M}$ .
输入格式
The first line of input contains three integers $n$ , $m$ and $v$ ( $1\leq n\leq 5000$ , $1\leq m,v\leq 10^9$ ).
The second line of input contains $n$ integers $a_1,a_2,\ldots,a_n$ ( $1\leq a_i\leq 10^9$ ).
The second line of input contains $n$ integers $a_1,a_2,\ldots,a_n$ ( $1\leq a_i\leq 10^9$ ).
输出格式
Output the expected value of $\prod_{i=1}^n a_i$ modulo $10^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 $a$ after performing all the $m$ operations :
1\. $a_1=2,a_2=12$ with $\frac{1}{4}$ probability.
2\. $a_1=a_2=12$ with $\frac{1}{4}$ probability.
3\. $a_1=7,a_2=12$ with $\frac{1}{2}$ probability.
So the expected value of $a_1\cdot a_2$ is $\frac{1}{4}\cdot (24+144) + \frac{1}{2}\cdot 84=84$ .
1\. $a_1=2,a_2=12$ with $\frac{1}{4}$ probability.
2\. $a_1=a_2=12$ with $\frac{1}{4}$ probability.
3\. $a_1=7,a_2=12$ with $\frac{1}{2}$ probability.
So the expected value of $a_1\cdot a_2$ is $\frac{1}{4}\cdot (24+144) + \frac{1}{2}\cdot 84=84$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted