QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#851591#8047. DFS Order 4jiamengtongWA 1ms4284kbC++14998b2025-01-10 20:47:542025-01-10 20:47:58

Judging History

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

  • [2025-01-10 20:47:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4284kb
  • [2025-01-10 20:47:54]
  • 提交

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 >= 0; 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: 3936kb

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 4284kb

input:

100 1000000007

output:

439293340

result:

wrong answer 1st numbers differ - expected: '270904395', found: '439293340'