# 题意

$\displaystyle S(i) = \sum _{j=1} ^ {n} \mathrm{dist}(i, j)^k$

$n ≤ 50000, k ≤ 150$

# 题解

$\displaystyle x^n=\sum_{k=0}^{n}\begin{Bmatrix} n \\ k \end{Bmatrix} x^{\underline k}=\sum _{k=0}^{n}(-1)^k \begin{Bmatrix} n \\ k \end{Bmatrix} x^{\overline k}$

$\displaystyle S(i)=\sum _{j=1}^{n}\sum_{l=0}^{k}\begin{Bmatrix} k \\ l \end{Bmatrix} \mathrm{dist}(i,j)^{\underline l}$

$\displaystyle S(i)=\sum_{l=0}^{k}\begin{Bmatrix} k \\ l \end{Bmatrix}\sum _{j=1}^{n} \mathrm{dist}(i,j)^{\underline l}$

$\displaystyle \binom n k = \frac{n!}{(n-k)!k!}=\frac{n^{\underline k}}{k!}$

$\therefore \displaystyle n^{\underline k}=\binom n k k!$

$\displaystyle S(i)=\sum_{l=0}^{k}\begin{Bmatrix} k \\ l \end{Bmatrix} l!\sum _{j=1}^{n} \binom {\mathrm{dist}(i,j)} l$

$\displaystyle \binom n k = \binom {n-1} {k} + \binom {n-1} {k-1}$

# 代码

/**************************************************************
Problem: 2159
Language: C++
Result: Accepted
Time:4156 ms
Memory:67680 kb
****************************************************************/

#include <bits/stdc++.h>
#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;

inline bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
inline bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

int x = 0, fh = 1; char ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
return x * fh;
}

void File() {
freopen ("2159.in", "r", stdin);
freopen ("2159.out", "w", stdout);
#endif
}

const int Mod = 10007, N = 50010;

vector<int> G[N];

int n, k, S[160][160];
int fac[160];

void Init(int maxn) {
S[0][0] = 1; For (i, 1, maxn) { S[i][1] = 1; For (j, 1, i) S[i][j] = (j * S[i - 1][j] % Mod + S[i - 1][j - 1]) % Mod; }
fac[0] = fac[1] = 1; For (i, 2, maxn) fac[i] = fac[i - 1] * i % Mod;
}

int f[N][160], sz[N];

void Dfs1(int u, int fa) {
f[u][0] = 1; sz[u] = 1;
For (i, 0, G[u].size() - 1) {
int v = G[u][i]; if (v == fa) continue ;
Dfs1(v, u); sz[u] += sz[v];
(f[u][0] += f[v][0]) %= Mod;
For (j, 1, k) (f[u][j] += f[v][j] + f[v][j - 1]) %= Mod;
}
}

int g[N][160];

void Dfs2(int u, int fa) {
g[u][0] = (n - sz[u]) % Mod;
if (fa) {
For (i, 1, k) {
g[u][i] = g[fa][i] + g[fa][i - 1];
g[u][i] += f[fa][i] - (f[u][i] + f[u][i - 1]);
g[u][i] += f[fa][i - 1] - (f[u][i - 1] + (i > 1 ? f[u][i - 2] : 0));
g[u][i] = (g[u][i] % Mod + Mod) % Mod;
}
}
For (i, 0, G[u].size() - 1) { int v = G[u][i]; if (v == fa) continue ; Dfs2(v, u); }
}

int ans[N];

inline void Input_Umcompress()
{
register int l, now, a, b, q, tmp, u, v;
For(i, 1, n - 1)
now = (now * a + b) % q, tmp = i < l ? i : l,
u = i - now % tmp, v = i + 1, G[u].push_back(v), G[v].push_back(u);
}

int main () {
File(); Init(150);
Input_Umcompress();
For (i, 1, n - 1) {
G[u].push_back(v);
G[v].push_back(u);
}*/

Dfs1(1, 0); Dfs2(1, 0);

For (i, 1, n) {
For (l, 0, k)
(ans[i] += S[k][l] * fac[l] % Mod * (f[i][l] + g[i][l]) % Mod) %= Mod;
printf ("%d\n", ans[i]);
}

return 0;
}

posted @ 2018-03-24 20:59  zjp_shadow  阅读(184)  评论(0编辑  收藏  举报