QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#851573 | #8047. DFS Order 4 | jiamengtong | WA | 1ms | 4372kb | C++14 | 998b | 2025-01-10 20:40:56 | 2025-01-10 20:41:04 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define M 805
using namespace std;
int n, mod, mul[M], inv[M], dp[M][M];
int qpow(int x, int ti)
{
int ret = 1;
while(ti)
{
if(ti & 1) ret = ret * x % mod;
x = x * x % mod;
ti >>= 1;
}
return ret;
}
signed main()
{
scanf("%lld%lld", &n, &mod);
if(n == 1) return puts("1"), 0;
mul[0] = 1;
for(int i = 1; i <= n; i++) mul[i] = mul[i - 1] * i % mod;
inv[n] = qpow(mul[n], mod - 2);
for(int i = n - 1; i >= 1; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
dp[0][0] = 1;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= i; j++)
{
dp[i][j] = dp[i - 1][j - 1];
for(int k = 1; k < i; k++) (dp[i][j] += dp[k][1] * dp[i - k - 1][j - 1]) % mod;
for(int k = 1; k < i - 1; k++) (dp[i][j] += dp[k][1] * dp[i - k - 1][j]) % mod;
(dp[i][j] += mod - dp[i - 1][j + 1]) %= mod;
(dp[i][j] *= inv[i] * mul[i - 1] % mod) %= mod;
}
}
printf("%lld\n", dp[n - 1][1] * mul[n - 1] % mod);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
input:
4 114514199
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3976kb
input:
10 998244353
output:
11033
result:
ok 1 number(s): "11033"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 4372kb
input:
100 1000000007
output:
439293340
result:
wrong answer 1st numbers differ - expected: '270904395', found: '439293340'