QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#333879#8047. DFS Order 4LarunatrecyTL 6ms3828kbC++14717b2024-02-20 18:27:392024-02-20 18:27:39

Judging History

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

  • [2024-02-20 18:27:39]
  • 评测
  • 测评结果:TL
  • 用时:6ms
  • 内存:3828kb
  • [2024-02-20 18:27:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 880;
int n,mod;
int inv[N];
int dp[N][N],f[N];//点数,层数 
int main()
{
	cin>>n>>mod;
	inv[1]=1;
	for(int i=2;i<=n;i++)inv[i]=1ll*inv[mod%i]*(mod-mod/i)%mod;
	dp[1][0]=1;
	for(int i=2;i<=n;i++)
	for(int j=0;j<=i;j++)
	{
		dp[i][j]=(dp[i][j]+1ll*dp[i-1][j+1]*inv[i]%mod)%mod;
		if(j==0)dp[i][0]=(dp[i][0]+1ll*dp[i-1][0]*inv[i]%mod)%mod;
		for(int k=1;k<i;k++)
		{
			dp[i][j]=(dp[i][j]+1ll*dp[i-k][j]*dp[k-1][0]%mod*inv[i]%mod)%mod;
			if(j)dp[i][j]=(dp[i][j]-1ll*dp[i-k][j-1]*(dp[k-1][0]+(k==1))%mod*inv[i]%mod)%mod;
		}
	} 
	int ans=1ll*dp[n-1][0]*inv[n]%mod;
	for(int i=1;i<=n;i++)ans=1ll*ans*i%mod;
	cout<<ans;
	return 0;
} 

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3656kb

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

score: 0
Accepted
time: 6ms
memory: 3828kb

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: -100
Time Limit Exceeded

input:

756 1001338769

output:


result: