QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#816319 | #9561. 树数叔术 | NineSuns | 100 ✓ | 122ms | 17728kb | C++14 | 1.0kb | 2024-12-16 09:20:18 | 2024-12-16 09:20:18 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define pii pair <int, int>
#define fi first
#define se second
#define pb push_back
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int N = 155;
int n, V, mod;
ll f[N][N][N], c[N][N], fac[N];
ll qpow (ll x, ll y = mod-2) {
ll res = 1;
while (y) {
if (y&1) res = res*x%mod;
x = x*x%mod; y >>= 1;
}
return res;
}
signed main () {
cin >> n >> V >> mod;
if (V >= n) {
cout << 0; return 0;
}
c[0][0] = 1; fac[0] = 1;
for (int i = 1;i <= n;i++) {
c[i][0] = 1; fac[i] = fac[i-1]*i%mod;
for (int j = 1;j <= i;j++) c[i][j] = (c[i-1][j]+c[i-1][j-1])%mod;
}
f[0][0][1] = 1;
for (int i = 0;i < V;i++) {
for (int j = 0;j <= n;j++) {
for (int z = 1;z <= n;z++) {
if (!f[i][j][z]) continue;
for (int p = 0;p+z+1 <= n;p++) (f[i+1][j+p][z+p+1] += z*f[i][j][z]) %= mod;
for (int p = 1;p <= j;p++) (f[i+1][j-p][z] += f[i][j][z]*c[j][p]) %= mod;
}
}
}
cout << f[V][0][n]*fac[n]%mod;
return 0;
}
詳細信息
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 1ms
memory: 3708kb
input:
1 1 624295285
output:
0
result:
ok single line: '0'
Test #2:
score: 5
Accepted
time: 0ms
memory: 3696kb
input:
4 684813415 564954712
output:
0
result:
ok single line: '0'
Test #3:
score: 5
Accepted
time: 0ms
memory: 3644kb
input:
4 2 844826878
output:
24
result:
ok single line: '24'
Test #4:
score: 5
Accepted
time: 0ms
memory: 3624kb
input:
4 17724073 252218682
output:
0
result:
ok single line: '0'
Test #5:
score: 5
Accepted
time: 0ms
memory: 3576kb
input:
4 3 697681963
output:
384
result:
ok single line: '384'
Subtask #2:
score: 15
Accepted
Test #6:
score: 15
Accepted
time: 0ms
memory: 3804kb
input:
6 4 956647977
output:
238320
result:
ok single line: '238320'
Test #7:
score: 15
Accepted
time: 0ms
memory: 3760kb
input:
6 450615260 491361886
output:
0
result:
ok single line: '0'
Test #8:
score: 15
Accepted
time: 0ms
memory: 3600kb
input:
6 5 339344353
output:
933120
result:
ok single line: '933120'
Test #9:
score: 15
Accepted
time: 0ms
memory: 3736kb
input:
6 3 842228619
output:
23760
result:
ok single line: '23760'
Test #10:
score: 15
Accepted
time: 0ms
memory: 3596kb
input:
6 5 331699652
output:
933120
result:
ok single line: '933120'
Subtask #3:
score: 30
Accepted
Test #11:
score: 30
Accepted
time: 2ms
memory: 6292kb
input:
48 26 424594716
output:
362283012
result:
ok single line: '362283012'
Test #12:
score: 30
Accepted
time: 0ms
memory: 3632kb
input:
49 1000000000 738885247
output:
0
result:
ok single line: '0'
Test #13:
score: 30
Accepted
time: 2ms
memory: 5012kb
input:
48 39 688951620
output:
598399200
result:
ok single line: '598399200'
Test #14:
score: 30
Accepted
time: 0ms
memory: 3556kb
input:
50 476039414 292870080
output:
0
result:
ok single line: '0'
Test #15:
score: 30
Accepted
time: 3ms
memory: 5320kb
input:
50 48 245196368
output:
123576912
result:
ok single line: '123576912'
Subtask #4:
score: 50
Accepted
Test #16:
score: 50
Accepted
time: 0ms
memory: 3696kb
input:
150 526250070 197316869
output:
0
result:
ok single line: '0'
Test #17:
score: 50
Accepted
time: 105ms
memory: 16924kb
input:
149 116 671784452
output:
18945228
result:
ok single line: '18945228'
Test #18:
score: 50
Accepted
time: 105ms
memory: 17040kb
input:
146 144 906402626
output:
438777234
result:
ok single line: '438777234'
Test #19:
score: 50
Accepted
time: 117ms
memory: 17336kb
input:
147 143 705666477
output:
70408701
result:
ok single line: '70408701'
Test #20:
score: 50
Accepted
time: 122ms
memory: 17728kb
input:
150 147 453481175
output:
336290325
result:
ok single line: '336290325'