E. Lust

Codeforces
IDCF891E
Time2000ms
Memory256MB
Difficulty
combinatoricsmathmatrices
English · Original
Chinese · Translation
Formal · Original
_A false witness that speaketh lies!_ You are given a sequence containing _n_ integers. There is a variable _res_ that is equal to 0 initially. The following process repeats _k_ times. Choose an index from 1 to _n_ uniformly at random. Name it _x_. Add to _res_ the multiply of all _a__i_'s such that 1 ≤ _i_ ≤ _n_, but _i_ ≠ _x_. Then, subtract _a__x_ by 1. You have to find expected value of _res_ at the end of the process. It can be proved that the expected value of _res_ can be represented as an irreducible fraction . You have to find . ## Input The first line contains two integers _n_ and _k_ (1 ≤ _n_ ≤ 5000, 1 ≤ _k_ ≤ 109) — the number of elements and parameter _k_ that is specified in the statement. The second line contains _n_ space separated integers _a_1, _a_2, ..., _a__n_ (0 ≤ _a__i_ ≤ 109). ## Output Output a single integer — the value . [samples]
_A false witness that speaketh lies!_ 给定一个包含 #cf_span[n] 个整数的序列。初始时有一个变量 #cf_span[res] 等于 #cf_span[0]。该过程重复 #cf_span[k] 次。 在 #cf_span[1] 到 #cf_span[n] 中均匀随机选择一个索引,记为 #cf_span[x]。将所有满足 #cf_span[1 ≤ i ≤ n] 且 #cf_span[i ≠ x] 的 #cf_span[ai] 的乘积加到 #cf_span[res] 上。然后,将 #cf_span[ax] 减去 #cf_span[1]。 你需要求出该过程结束后 #cf_span[res] 的期望值。可以证明,#cf_span[res] 的期望值可以表示为一个既约分数 。你需要求出 。 第一行包含两个整数 #cf_span[n] 和 #cf_span[k] (#cf_span[1 ≤ n ≤ 5000], #cf_span[1 ≤ k ≤ 109]) —— 元素个数和题目中指定的参数 #cf_span[k]。 第二行包含 #cf_span[n] 个空格分隔的整数 #cf_span[a1, a2, ..., an] (#cf_span[0 ≤ ai ≤ 109])。 输出一个整数 —— 的值。 ## Input 第一行包含两个整数 #cf_span[n] 和 #cf_span[k] (#cf_span[1 ≤ n ≤ 5000], #cf_span[1 ≤ k ≤ 109]) —— 元素个数和题目中指定的参数 #cf_span[k]。第二行包含 #cf_span[n] 个空格分隔的整数 #cf_span[a1, a2, ..., an] (#cf_span[0 ≤ ai ≤ 109])。 ## Output 输出一个整数 —— 的值。 [samples]
**Definitions** Let $ n, k \in \mathbb{Z}^+ $ with $ 1 \leq n \leq 5000 $, $ 1 \leq k \leq 10^9 $. Let $ \mathbf{a} = (a_1, a_2, \dots, a_n) \in \mathbb{Z}_{\geq 0}^n $ be the initial sequence. Let $ R $ be the random variable denoting the final value of `res` after $ k $ iterations. **Process** At each iteration: - Choose index $ x \in \{1, \dots, n\} $ uniformly at random. - Add to `res` the value $ \prod_{\substack{i=1 \\ i \neq x}}^n a_i $. - Decrement $ a_x \leftarrow a_x - 1 $. **Objective** Compute $ \mathbb{E}[R] \mod (10^9 + 7) $, where $ \mathbb{E}[R] = \frac{p}{q} $ is the expected value in irreducible form, and output $ p \cdot q^{-1} \mod (10^9 + 7) $.
Samples
Input #1
2 1
5 5
Output #1
5
Input #2
1 10
80
Output #2
10
Input #3
2 2
0 0
Output #3
500000003
Input #4
9 4
0 11 12 9 20 7 8 18 2
Output #4
169316356
API Response (JSON)
{
  "problem": {
    "name": "E. Lust",
    "description": {
      "content": "_A false witness that speaketh lies!_ You are given a sequence containing _n_ integers. There is a variable _res_ that is equal to 0 initially. The following process repeats _k_ times. Choose an ind",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF891E"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "_A false witness that speaketh lies!_\n\nYou are given a sequence containing _n_ integers. There is a variable _res_ that is equal to 0 initially. The following process repeats _k_ times.\n\nChoose an ind...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "_A false witness that speaketh lies!_\n\n给定一个包含 #cf_span[n] 个整数的序列。初始时有一个变量 #cf_span[res] 等于 #cf_span[0]。该过程重复 #cf_span[k] 次。\n\n在 #cf_span[1] 到 #cf_span[n] 中均匀随机选择一个索引,记为 #cf_span[x]。将所有满足 #cf_span[1 ≤ i...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n, k \\in \\mathbb{Z}^+ $ with $ 1 \\leq n \\leq 5000 $, $ 1 \\leq k \\leq 10^9 $.  \nLet $ \\mathbf{a} = (a_1, a_2, \\dots, a_n) \\in \\mathbb{Z}_{\\geq 0}^n $ be the initial sequence.  \n...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments