QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#737094#9561. 树数叔术ANIG50 173ms13932kbC++141004b2024-11-12 14:36:472024-11-12 14:36:59

Judging History

你现在查看的是最新测评结果

  • [2024-11-12 14:36:59]
  • 评测
  • 测评结果:50
  • 用时:173ms
  • 内存:13932kb
  • [2024-11-12 14:36:47]
  • 提交

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],g[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=0;l+j<=n;l++){
					for(int r=0;r<=k;r++){
						f[i+1][j+l][k-r]+=f[i][j][k]*C[k][r]%mods*C[l+j-2][j-2]%mods*C[n-j][l]%mods*jc[l]%mods;
					}
				}
				f[i+1][j][k]-=f[i][j][k];
			}
		}
		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+2][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<<(f[m][n][0]+mods)%mods;
}

详细

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 1ms
memory: 5700kb

input:

1 1 624295285

output:

0

result:

ok single line: '0'

Test #2:

score: 5
Accepted
time: 0ms
memory: 3644kb

input:

4 684813415 564954712

output:

0

result:

ok single line: '0'

Test #3:

score: 5
Accepted
time: 1ms
memory: 5660kb

input:

4 2 844826878

output:

24

result:

ok single line: '24'

Test #4:

score: 5
Accepted
time: 0ms
memory: 3632kb

input:

4 17724073 252218682

output:

0

result:

ok single line: '0'

Test #5:

score: 5
Accepted
time: 1ms
memory: 9780kb

input:

4 3 697681963

output:

384

result:

ok single line: '384'

Subtask #2:

score: 15
Accepted

Test #6:

score: 15
Accepted
time: 1ms
memory: 9772kb

input:

6 4 956647977

output:

238320

result:

ok single line: '238320'

Test #7:

score: 15
Accepted
time: 0ms
memory: 3716kb

input:

6 450615260 491361886

output:

0

result:

ok single line: '0'

Test #8:

score: 15
Accepted
time: 1ms
memory: 7756kb

input:

6 5 339344353

output:

933120

result:

ok single line: '933120'

Test #9:

score: 15
Accepted
time: 1ms
memory: 5692kb

input:

6 3 842228619

output:

23760

result:

ok single line: '23760'

Test #10:

score: 15
Accepted
time: 1ms
memory: 9860kb

input:

6 5 331699652

output:

933120

result:

ok single line: '933120'

Subtask #3:

score: 30
Accepted

Test #11:

score: 30
Accepted
time: 82ms
memory: 9840kb

input:

48 26 424594716

output:

362283012

result:

ok single line: '362283012'

Test #12:

score: 30
Accepted
time: 0ms
memory: 3572kb

input:

49 1000000000 738885247

output:

0

result:

ok single line: '0'

Test #13:

score: 30
Accepted
time: 120ms
memory: 13932kb

input:

48 39 688951620

output:

598399200

result:

ok single line: '598399200'

Test #14:

score: 30
Accepted
time: 0ms
memory: 3516kb

input:

50 476039414 292870080

output:

0

result:

ok single line: '0'

Test #15:

score: 30
Accepted
time: 173ms
memory: 13860kb

input:

50 48 245196368

output:

123576912

result:

ok single line: '123576912'

Subtask #4:

score: 0
Time Limit Exceeded

Test #16:

score: 50
Accepted
time: 0ms
memory: 3692kb

input:

150 526250070 197316869

output:

0

result:

ok single line: '0'

Test #17:

score: 0
Time Limit Exceeded

input:

149 116 671784452

output:


result: