-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctional Graph Distribution.cpp
More file actions
executable file
·76 lines (67 loc) · 1.29 KB
/
Copy pathFunctional Graph Distribution.cpp
File metadata and controls
executable file
·76 lines (67 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
LL fact[5009];
LL inv[5009];
LL pown[5009];
LL stirling[5009][5009];
void stirling_first_kind() {
stirling[1][1] = 1;
for (int n = 2; n < 5009; n++) {
for (int k = 1; k <= n; k++) {
stirling[n][k] = (stirling[n - 1][k - 1] - stirling[n - 1][k] * (n - 1)) % MOD;
}
}
}
inline LL modmult(const LL a, const LL b) {
return a * b % MOD;
}
LL exp(LL a, LL b) {
LL res = 1;
while (b) {
if (b & 1) {
res = (res * a) % MOD;
}
b >>= 1;
a = (a * a) % MOD;
}
return res;
}
inline LL inverse(LL a) {
return exp(a, MOD - 2);
}
LL bc(LL n, LL k) {
return fact[n] * inv[k] % MOD * inv[n - k] % MOD;
}
void init(int n) {
stirling_first_kind();
fact[0] = 1;
for (int i = 1; i < 5009; i++) {
fact[i] = (fact[i - 1] * i) % MOD;
}
inv[0] = 1;
for (int i = 1; i < 5009; i++) {
inv[i] = inverse(fact[i]);
}
for (int i = 0; i < 5009; i++) {
pown[i] = exp(n, i);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
LL n;
cin >> n;
init(n);
// https://oeis.org/A060281
for (int k = 1; k <= n; k++) {
LL res = 0;
for (int j = 0; j < n; j++) {
res = (res + bc(n - 1, j) * modmult(pown[n - 1 - j], abs(stirling[j + 1][k]))) % MOD;
}
cout << res << " ";
}
return 0;
}