QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#333879 | #8047. DFS Order 4 | Larunatrecy | TL | 6ms | 3828kb | C++14 | 717b | 2024-02-20 18:27:39 | 2024-02-20 18:27:39 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
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