QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#764728 | #8047. DFS Order 4 | To_our_starry_sea | AC ✓ | 371ms | 8648kb | C++14 | 1.3kb | 2024-11-20 10:27:31 | 2024-11-20 10:27:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = 805;
int n;
ll MOD, dp[MAXN][MAXN], jc[MAXN], ni[MAXN];
inline ll read() {
ll x = 0, f = 1; char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * f;
}
int main() {
n = read(), MOD = read();
jc[0] = jc[1] = ni[0] = ni[1] = 1;
for (ll i = 2; i <= n; i++) jc[i] = jc[i - 1] * i % MOD, ni[i] = (MOD - MOD / i) * ni[MOD % i] % MOD;
dp[0][1] = dp[1][0] = dp[1][1] = 1;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= min(i - 1, n - i + 1); j++) dp[i][j - 1] = dp[i - 1][j] * ni[i] % MOD;
for (int j = 1; j <= min(i, n - i + 1); j++) {
ll res = 0;
for (int k = 2; k <= i - 1; k++) res = (res + dp[k - 1][1] * dp[i - k][j] % MOD) % MOD;
dp[i][j] = (dp[i][j] + res * ni[i] % MOD) % MOD;
if (j != min(i, n - i + 1)) dp[i][j + 1] = (dp[i][j + 1] - (res + dp[i - 1][j]) % MOD * ni[i] % MOD + MOD) % MOD;
}
dp[i][1] = (dp[i][1] + dp[i][0]) % MOD;
}
printf("%lld\n", dp[n][0] * jc[n] % MOD);
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3852kb
input:
4 114514199
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
10 998244353
output:
11033
result:
ok 1 number(s): "11033"
Test #3:
score: 0
Accepted
time: 0ms
memory: 6036kb
input:
100 1000000007
output:
270904395
result:
ok 1 number(s): "270904395"
Test #4:
score: 0
Accepted
time: 314ms
memory: 8328kb
input:
756 1001338769
output:
901942543
result:
ok 1 number(s): "901942543"
Test #5:
score: 0
Accepted
time: 362ms
memory: 8588kb
input:
793 1009036033
output:
301770320
result:
ok 1 number(s): "301770320"
Test #6:
score: 0
Accepted
time: 314ms
memory: 8000kb
input:
759 1005587659
output:
846376219
result:
ok 1 number(s): "846376219"
Test #7:
score: 0
Accepted
time: 336ms
memory: 8092kb
input:
773 1007855479
output:
1398019
result:
ok 1 number(s): "1398019"
Test #8:
score: 0
Accepted
time: 308ms
memory: 7880kb
input:
751 1006730639
output:
321287237
result:
ok 1 number(s): "321287237"
Test #9:
score: 0
Accepted
time: 342ms
memory: 8112kb
input:
778 1007760653
output:
430322899
result:
ok 1 number(s): "430322899"
Test #10:
score: 0
Accepted
time: 365ms
memory: 8236kb
input:
798 1007543827
output:
688720826
result:
ok 1 number(s): "688720826"
Test #11:
score: 0
Accepted
time: 366ms
memory: 8648kb
input:
796 1004841413
output:
258829347
result:
ok 1 number(s): "258829347"
Test #12:
score: 0
Accepted
time: 338ms
memory: 8412kb
input:
775 1005185189
output:
744278608
result:
ok 1 number(s): "744278608"
Test #13:
score: 0
Accepted
time: 371ms
memory: 8596kb
input:
800 1006012831
output:
508549367
result:
ok 1 number(s): "508549367"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
1 1001338769
output:
1
result:
ok 1 number(s): "1"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
2 1001338769
output:
1
result:
ok 1 number(s): "1"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3948kb
input:
9 1009036033
output:
1780
result:
ok 1 number(s): "1780"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
14 1001338769
output:
43297358
result:
ok 1 number(s): "43297358"
Extra Test:
score: 0
Extra Test Passed