QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#723153 | #9561. 树数叔术 | dalao_see_me | 100 ✓ | 1522ms | 18084kb | C++14 | 2.3kb | 2024-11-07 21:17:35 | 2024-11-07 21:17:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int read() {
int x = 0, f = 1; char c = getchar();
while (c < '0' || c > '9') {if (c == '-') f = -f; c = getchar();}
while (c >= '0' && c <= '9') {x = x * 10 + (c ^ 48); c = getchar();}
return x * f;
}
const int N = 155;
int n, V, mod;
int C[N][N], f[N][N][N], g[N][N][3], fac[N], t[N][N];
void Solve() {
n = read(); V = read(); mod = read();
if (V >= n) return void(puts("0"));
f[0][1][0] = C[0][0] = fac[0] = 1;
for (int i = 1; i <= n; i++) fac[i] = 1LL * fac[i - 1] * i % mod;
for (int i = 1; i <= n; i++) {
C[i][0] = 1;
for (int j = 1; j <= i; j++) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
}
for (int i = 0; i <= n; i++) {
t[i][0] = 1;
for (int j = 1; j <= n; j++) t[i][j] = 1LL * t[i][j - 1] * (i + j - 1) % mod;
}
for (int i = 0; i < V; i++) {
for (int j = 0; j <= n; j++)
for (int k = 0; j + k <= n; k++)
g[j][k][0] = g[j][k][1] = g[j][k][2] = 0;
for (int j = 1; j <= n; j++)
for (int k = 0; j + k <= n; k++)
for (int c = 0; j + k + c <= n; c++)
g[j + c][k][min(c, 2)] = (g[j + c][k][min(c, 2)] + 1LL * f[i][j][k] * C[j + c][c] % mod * t[j + k - 1][c]) % mod;
for (int j = 1; j <= n; j++)
for (int k = 0; j + k <= n; k++)
for (int c = 0; c <= k; c++) {
int s = g[j][k][2]; if (c) s = (s + g[j][k][1]) % mod; if (c > 1) s = (s + g[j][k][0]) % mod;
f[i + 1][j + c][k - c] = (f[i + 1][j + c][k - c] + 1LL * s * C[k][c] % mod * fac[c] % mod * C[j + c][c]) % mod;
}
for (int j = 1; j <= n; j++)
for (int k = 0; j + k <= n; k++) {
f[i + 1][j + 1][k] = (f[i + 1][j + 1][k] + 1LL * f[i][j][k] * (j + k + j + k - 1) * (j + 1)) % mod;
f[i + 1][j + 1][k + 1] = (f[i + 1][j + 1][k + 1] + 1LL * f[i][j][k] * (j + k - 1) * (j + 1)) % mod;
if (k) f[i + 1][j + 1][k - 1] = (f[i + 1][j + 1][k - 1] + 1LL * f[i][j][k] * k * (j + 1)) % mod;
}
}
printf("%d\n", f[V][n][0]);
}
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
int _ = 1;
while (_--) Solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 0ms
memory: 3572kb
input:
1 1 624295285
output:
0
result:
ok single line: '0'
Test #2:
score: 5
Accepted
time: 0ms
memory: 3640kb
input:
4 684813415 564954712
output:
0
result:
ok single line: '0'
Test #3:
score: 5
Accepted
time: 0ms
memory: 3884kb
input:
4 2 844826878
output:
24
result:
ok single line: '24'
Test #4:
score: 5
Accepted
time: 0ms
memory: 3648kb
input:
4 17724073 252218682
output:
0
result:
ok single line: '0'
Test #5:
score: 5
Accepted
time: 0ms
memory: 3872kb
input:
4 3 697681963
output:
384
result:
ok single line: '384'
Subtask #2:
score: 15
Accepted
Test #6:
score: 15
Accepted
time: 0ms
memory: 3880kb
input:
6 4 956647977
output:
238320
result:
ok single line: '238320'
Test #7:
score: 15
Accepted
time: 0ms
memory: 3512kb
input:
6 450615260 491361886
output:
0
result:
ok single line: '0'
Test #8:
score: 15
Accepted
time: 0ms
memory: 3828kb
input:
6 5 339344353
output:
933120
result:
ok single line: '933120'
Test #9:
score: 15
Accepted
time: 0ms
memory: 3824kb
input:
6 3 842228619
output:
23760
result:
ok single line: '23760'
Test #10:
score: 15
Accepted
time: 0ms
memory: 3828kb
input:
6 5 331699652
output:
933120
result:
ok single line: '933120'
Subtask #3:
score: 30
Accepted
Test #11:
score: 30
Accepted
time: 10ms
memory: 4852kb
input:
48 26 424594716
output:
362283012
result:
ok single line: '362283012'
Test #12:
score: 30
Accepted
time: 0ms
memory: 3512kb
input:
49 1000000000 738885247
output:
0
result:
ok single line: '0'
Test #13:
score: 30
Accepted
time: 15ms
memory: 6640kb
input:
48 39 688951620
output:
598399200
result:
ok single line: '598399200'
Test #14:
score: 30
Accepted
time: 0ms
memory: 3636kb
input:
50 476039414 292870080
output:
0
result:
ok single line: '0'
Test #15:
score: 30
Accepted
time: 21ms
memory: 5644kb
input:
50 48 245196368
output:
123576912
result:
ok single line: '123576912'
Subtask #4:
score: 50
Accepted
Test #16:
score: 50
Accepted
time: 0ms
memory: 3692kb
input:
150 526250070 197316869
output:
0
result:
ok single line: '0'
Test #17:
score: 50
Accepted
time: 1173ms
memory: 15236kb
input:
149 116 671784452
output:
18945228
result:
ok single line: '18945228'
Test #18:
score: 50
Accepted
time: 1380ms
memory: 17600kb
input:
146 144 906402626
output:
438777234
result:
ok single line: '438777234'
Test #19:
score: 50
Accepted
time: 1394ms
memory: 17620kb
input:
147 143 705666477
output:
70408701
result:
ok single line: '70408701'
Test #20:
score: 50
Accepted
time: 1522ms
memory: 18084kb
input:
150 147 453481175
output:
336290325
result:
ok single line: '336290325'