# 「codeforces - 1025G」Company Acquisitions

## description

$n$ 个人，一开始每个人都未被领导。

## solution

$\begin{cases} \mathbb E(|X_t|) < \infin\\ \mathbb E(X_{t + 1} - X_t | X_0,\dots X_t) = 0 \end{cases}$

$\mathbb E(X_{\tau}) = \mathbb E(X_0)$

\begin{aligned} \sum_{i=1}^{k}f(a_i)&=\frac{1}{k(k-1)}\sum_{p\not =q}\left( (\sum_{i\not=p,i\not=q}f(a_i)) + (a_p\times f(0)) + f(a_q+1)\right) + 1 \\ &= (1-\frac{2}{k})\times\sum_{i=1}^{k}f(a_i)+\frac{1}{k}\times\sum_{i=1}^{k} f(a_i+1)+\frac{n-k}{k}\times f(0)+1 \\ -k &=\sum_{i=1}^{k}(f(a_i+1)-2\times f(a_i))+\frac{n-k}{k}\times f(0) \end{aligned}

## code

#include <cstdio>
#include <algorithm>
using namespace std;

const int N = 500;
const int P = int(1E9) + 7;

inline int add(int x, int y) {x += y; return x >= P ? x - P : x;}
inline int sub(int x, int y) {x -= y; return x < 0 ? x + P : x;}
inline int mul(int x, int y) {return (int)(1LL * x * y % P);}
int mpow(int b, int p) {
int r; for(r = 1; p; p >>= 1, b = mul(b, b))
if( p & 1 ) r = mul(r, b);
return r;
}

int c[N + 5], a[N + 5], n;
int main() {
scanf("%d", &n);
for(int i=1;i<=n;i++) {
scanf("%d", &a[i]);
if( a[i] != -1 ) c[a[i]]++;
}
int phi0 = 0;
for(int i=1;i<=n;i++)
phi0 = add(phi0, sub(1, mpow(2, c[i])));
int phiT = sub(1, mpow(2, n - 1));
printf("%d\n", sub(phi0, phiT));
}


## details

posted @ 2020-07-19 16:06  Tiw_Air_OAO  阅读(25)  评论(0编辑  收藏