QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#461867 | #2438. Minimum Spanning Trees | alpha1022 | WA | 53ms | 4160kb | C++14 | 3.4kb | 2024-07-03 08:41:18 | 2024-07-03 08:41:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
void add(int &x, int y) { if ((x += y - mod) < 0) x += mod; }
void sub(int &x, int y) { if ((x -= y) < 0) x += mod; }
int mpow(int a, int b) {
int ret = 1;
for (; b; b >>= 1) {
if (b & 1) ret = (ll)ret * a % mod;
a = (ll)a * a % mod;
}
return ret;
}
const int K = 4;
const int N = 40;
const int S = K * N;
const int LIM = N * (N - 1) / 2;
int n, k, tk;
int p[K + 5], fac[N + 5], ifac[N + 5], inv[N + 5];
int pw[LIM + 5], ipw[LIM + 5];
int f[K + 5][N + 5][S + 5], g[N + 5][S + 5], h[N + 5][S + 5];
int ans[S + 5];
void solve() {
scanf("%d%d", &n, &k); int nv = mpow(100, mod - 2);
for (int i = 0; i <= k; ++i) scanf("%d", p + i), p[i] = (ll)p[i] * nv % mod;
for (tk = k; !p[k]; --k);
fac[0] = 1;
for (int i = 1; i <= n; ++i) fac[i] = (ll)fac[i - 1] * i % mod;
ifac[n] = mpow(fac[n], mod - 2);
for (int i = n; i; --i) ifac[i - 1] = (ll)ifac[i] * i % mod;
for (int i = 1; i <= n; ++i) inv[i] = (ll)ifac[i] * fac[i - 1] % mod;
memset(f, 0, sizeof f);
f[0][1][0] = 1;
for (int v = 1, q = 1; v <= k; ++v) {
int iq = mpow(q, mod - 2);
pw[0] = ipw[0] = 1;
for (int i = 1; i <= n * (n - 1) / 2; ++i)
pw[i] = (ll)pw[i - 1] * q % mod,
ipw[i] = (ll)ipw[i - 1] * iq % mod;
memset(h, 0, sizeof h);
for (int i = 1; i <= n; ++i)
for (int s = 0; s <= (v - 1) * (i - 1); ++s)
if (f[v - 1][i][s])
h[i][s + v] = (ll)f[v - 1][i][s] * ipw[i * (i - 1) / 2] % mod;
memset(g, 0, sizeof g), g[0][0] = 1;
for (int i = 1; i <= n; ++i)
for (int s = 0; s <= v * i; ++s) {
for (int j = 1; j <= i; ++j)
for (int t = 0; t <= (v - 1) * j + 1 && t <= s; ++t)
if (h[j][t] && g[i - j][s - t])
g[i][s] = (g[i][s] + (ll)j * h[j][t] % mod * g[i - j][s - t]) % mod;
g[i][s] = (ll)g[i][s] * inv[i] % mod;
}
for (int i = 0; i <= n; ++i)
for (int s = 0; s <= v * i; ++s)
g[i][s] = (ll)g[i][s] * pw[i * (i - 1) / 2] % mod;
if (p[0] == 0 && v == k) {
for (int i = 1; i <= n; ++i)
for (int s = v; s <= v * i; ++s)
f[v][i][s - v] = g[i][s];
break;
}
sub(q, p[v]), iq = mpow(q, mod - 2);
for (int i = 1; i <= n * (n - 1) / 2; ++i)
pw[i] = (ll)pw[i - 1] * q % mod,
ipw[i] = (ll)ipw[i - 1] * iq % mod;
for (int i = 0; i <= n; ++i)
for (int s = 0; s <= v * i; ++s)
g[i][s] = (ll)g[i][s] * ipw[i * (i - 1) / 2] % mod;
memset(h, 0, sizeof h);
for (int i = 1; i <= n; ++i)
for (int s = 0; s <= v * i; ++s) {
h[i][s] = (ll)g[i][s] * i % mod;
for (int j = 1; j < i; ++j)
for (int t = 0; t <= v * j && t <= s; ++t)
if (h[j][t] && g[i - j][s - t])
h[i][s] = (h[i][s] + (ll)(mod - j) * h[j][t] % mod * g[i - j][s - t]) % mod;
h[i][s] = (ll)h[i][s] * inv[i] % mod;
}
for (int i = 1; i <= n; ++i)
for (int s = v; s <= v * i; ++s)
f[v][i][s - v] = (ll)h[i][s] * pw[i * (i - 1) / 2] % mod;
}
for (int i = 0; i <= k * (n - 1); ++i) ans[i] = (ll)f[k][n][i] * fac[n] % mod;
k = tk;
for (int i = n - 1; i <= k * (n - 1); ++i) printf("%d%c", ans[i], " \n"[i == k * (n - 1)]);
}
int T;
int main() {
for (scanf("%d", &T); T; --T) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 53ms
memory: 4160kb
input:
200 3 1 50 50 3 2 0 50 50 3 3 25 25 25 25 8 1 41 59 7 3 37 30 7 26 3 3 16 12 18 54 9 2 9 43 48 9 3 3 40 42 15 9 1 29 71 9 2 40 42 18 5 1 76 24 5 1 39 61 9 2 23 38 39 10 4 18 15 34 2 31 7 2 23 28 49 9 4 15 13 25 19 28 7 1 64 36 6 1 50 50 9 1 4 96 4 1 64 36 9 2 24 45 31 9 2 3 61 36 9 1 65 35 8 4 6 1 3...
output:
500000004 500000004 375000003 125000001 406250003 109375001 250000002 265625002 562500004 858129220 40267248 73443306 307645653 13908396 542571454 781149891 223877799 478284083 469782292 483514097 271207900 851118600 686534546 708608005 271088002 536992004 107032001 243224002 763536836 20527108 7248...
result:
wrong answer 78th lines differ - expected: '328083993 0 0 0 0 0 0 0', found: '328083993 849501245 772517571 ...6 434269427 517039200 100423093'