CF1575F.Finding Expected Value
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Mr. Chanek opened a letter from his fellow, who is currently studying at Singanesia. Here is what it says.
Define an array b ( 0≤bi<k ) with n integers. While there exists a pair (i,j) such that bi=bj , do the following operation:
- Randomly pick a number i satisfying 0≤i<n . Note that each number i has a probability of n1 to be picked.
- Randomly Pick a number j satisfying 0≤j<k .
- Change the value of bi to j . It is possible for bi to be changed to the same value.
Denote f(b) as the expected number of operations done to b until all elements of b are equal.
You are given two integers n and k , and an array a ( −1≤ai<k ) of n integers.
For every index i with ai=−1 , replace ai with a random number j satisfying 0≤j<k . Let c be the number of occurrences of −1 in a . There are kc possibilites of a after the replacement, each with equal probability of being the final array.
Find the expected value of f(a) 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 such an integer x that 0≤x<M and x⋅q≡p(modM) .
After reading the letter, Mr. Chanek gave the task to you. Solve it for the sake of their friendship!
输入格式
The first line contains two integers n and k ( 2≤n≤105 , 2≤k≤109 ).
The second line contains n integers a1,a2,…,an ( −1≤ai<k ).
输出格式
Output an integer denoting the expected value of f(a) modulo 109+7 .
输入输出样例
输入#1
2 2 0 1
输出#1
2
输入#2
2 2 0 -1
输出#2
1
输入#3
3 3 0 1 1
输出#3
12
输入#4
3 3 -1 -1 -1
输出#4
11
输入#5
10 9 -1 0 -1 1 1 2 2 3 3 3
输出#5
652419213