QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#737038 | #9561. 树数叔术 | ANIG | 5 | 43ms | 8360kb | C++14 | 1021b | 2024-11-12 14:21:08 | 2024-11-12 14:21:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=155;
int n,m,mods,C[N][N],f[N][N][N],jc[N];
signed main(){
cin>>n>>m>>mods;
if(m>n){
cout<<"0";
return 0;
}
for(int i=0;i<=n;i++)C[i][0]=1;
jc[0]=1;
for(int i=1;i<=n;i++){
jc[i]=jc[i-1]*i%mods;
for(int j=1;j<=n;j++){
C[i][j]=(C[i-1][j]+C[i-1][j-1])%mods;
}
}
f[0][1][0]=n;
for(int i=0;i<m;i++){
for(int j=2;j<=n;j++){
for(int k=0;k<=j;k++){
for(int l=1;l+j<=n;l++){
for(int r=0;r<=l&&r<=k;r++){
f[i+1][j+l][k-r]+=f[i][j][k]*C[k][r]%mods*C[l-r+j-2][j-2]%mods*C[n-j][l-r]%mods*jc[l-r]%mods;
}
}
}
}
for(int j=1;j<=n;j++){
for(int k=0;k<=j;k++){
f[i+1][j+1][k]+=f[i][j][k]*j%mods*(n-j)%mods;
f[i+1][j+1][k+1]+=f[i][j][k]*(j-1)%mods*(n-j)%mods*(n-j-1)%mods;
}
}
for(int j=1;j<=n;j++){
for(int k=0;k<=j;k++){
f[i+1][j][k]%=mods;
// cout<<i+1<<" "<<j<<" "<<k<<" "<<f[i+1][j][k]<<endl;
}
}
}
cout<<f[m][n][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: 3712kb
input:
1 1 624295285
output:
0
result:
ok single line: '0'
Test #2:
score: 5
Accepted
time: 0ms
memory: 3708kb
input:
4 684813415 564954712
output:
0
result:
ok single line: '0'
Test #3:
score: 5
Accepted
time: 0ms
memory: 5632kb
input:
4 2 844826878
output:
24
result:
ok single line: '24'
Test #4:
score: 5
Accepted
time: 0ms
memory: 3584kb
input:
4 17724073 252218682
output:
0
result:
ok single line: '0'
Test #5:
score: 5
Accepted
time: 0ms
memory: 3672kb
input:
4 3 697681963
output:
384
result:
ok single line: '384'
Subtask #2:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 0ms
memory: 3632kb
input:
6 4 956647977
output:
263520
result:
wrong answer 1st lines differ - expected: '238320', found: '263520'
Subtask #3:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 43ms
memory: 8360kb
input:
48 26 424594716
output:
50042340
result:
wrong answer 1st lines differ - expected: '362283012', found: '50042340'
Subtask #4:
score: 0
Time Limit Exceeded
Test #16:
score: 50
Accepted
time: 0ms
memory: 3572kb
input:
150 526250070 197316869
output:
0
result:
ok single line: '0'
Test #17:
score: 0
Time Limit Exceeded
input:
149 116 671784452