QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#781218 | #9561. 树数叔术 | qojszt | 100 ✓ | 122ms | 11164kb | C++14 | 1.5kb | 2024-11-25 15:17:22 | 2024-11-25 15:17:24 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n, v, M, C[160][160], fcn;
int f[160][160][160];//weight<=i,block sz = j,cnt >i = k
//ignore label 1~n,ans mul n!
int add(int x, int y){x += y;return x >= M? x - M : x;}
int mul(int x, int y){return static_cast<long long>(x) * y % M;}
void sadd(int &x, int y){x = add(x, y);}
int main(){
//freopen("c.in", "r", stdin);freopen("c.out", "w", stdout);
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
cin >> n >> v >> M;if (n <= v)return cout << 0 << endl, 0;
for (int i = 0; i <= n; fcn = i++? i <= n? mul(fcn, i) : fcn : 1)
for (int j = C[i][0] = 1; j <= i; ++j)C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]);
f[0][1][0] = 1;//must have weight 0
for (int i = 0; i < v; ++i)
for (int j = 1; j <= n; ++j)
for (int k = 0; k <= j; ++k)
if (f[i][j][k]){
for (int l = 1; l <= k; ++l)//fill `l` pts with i+1
sadd(f[i + 1][j][k - l/*used l poses*/], mul(f[i][j][k], C[k][l]/*choose poses of l pts*/));
for (int l = 1; j + l <= n; ++l)//add a list,length=l,include pts i+1
sadd(f[i + 1][j + l][k + l - 1], mul(f[i][j][k], j/*choose list's begin*/));
}
cout << mul(f[v][n][0], fcn/*n! choices of label*/) << endl;
return 0;
}
/*
5 3 998244353
2280
10 6 998244353
730523983
43 21 10091121
1515927
110 75 81670423
66351113
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 0ms
memory: 3692kb
input:
1 1 624295285
output:
0
result:
ok single line: '0'
Test #2:
score: 5
Accepted
time: 0ms
memory: 3576kb
input:
4 684813415 564954712
output:
0
result:
ok single line: '0'
Test #3:
score: 5
Accepted
time: 0ms
memory: 3660kb
input:
4 2 844826878
output:
24
result:
ok single line: '24'
Test #4:
score: 5
Accepted
time: 0ms
memory: 3576kb
input:
4 17724073 252218682
output:
0
result:
ok single line: '0'
Test #5:
score: 5
Accepted
time: 0ms
memory: 3656kb
input:
4 3 697681963
output:
384
result:
ok single line: '384'
Subtask #2:
score: 15
Accepted
Test #6:
score: 15
Accepted
time: 0ms
memory: 3676kb
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: 3640kb
input:
6 5 339344353
output:
933120
result:
ok single line: '933120'
Test #9:
score: 15
Accepted
time: 0ms
memory: 3684kb
input:
6 3 842228619
output:
23760
result:
ok single line: '23760'
Test #10:
score: 15
Accepted
time: 0ms
memory: 3632kb
input:
6 5 331699652
output:
933120
result:
ok single line: '933120'
Subtask #3:
score: 30
Accepted
Test #11:
score: 30
Accepted
time: 2ms
memory: 4332kb
input:
48 26 424594716
output:
362283012
result:
ok single line: '362283012'
Test #12:
score: 30
Accepted
time: 0ms
memory: 3648kb
input:
49 1000000000 738885247
output:
0
result:
ok single line: '0'
Test #13:
score: 30
Accepted
time: 2ms
memory: 4404kb
input:
48 39 688951620
output:
598399200
result:
ok single line: '598399200'
Test #14:
score: 30
Accepted
time: 0ms
memory: 3588kb
input:
50 476039414 292870080
output:
0
result:
ok single line: '0'
Test #15:
score: 30
Accepted
time: 2ms
memory: 4536kb
input:
50 48 245196368
output:
123576912
result:
ok single line: '123576912'
Subtask #4:
score: 50
Accepted
Test #16:
score: 50
Accepted
time: 0ms
memory: 3652kb
input:
150 526250070 197316869
output:
0
result:
ok single line: '0'
Test #17:
score: 50
Accepted
time: 118ms
memory: 10720kb
input:
149 116 671784452
output:
18945228
result:
ok single line: '18945228'
Test #18:
score: 50
Accepted
time: 101ms
memory: 10972kb
input:
146 144 906402626
output:
438777234
result:
ok single line: '438777234'
Test #19:
score: 50
Accepted
time: 110ms
memory: 11144kb
input:
147 143 705666477
output:
70408701
result:
ok single line: '70408701'
Test #20:
score: 50
Accepted
time: 122ms
memory: 11164kb
input:
150 147 453481175
output:
336290325
result:
ok single line: '336290325'