QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#339710#8047. DFS Order 4yhk1001Compile Error//C++141.3kb2024-02-27 20:24:202024-02-27 20:24:20

Judging History

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

  • [2024-02-27 20:24:20]
  • 评测
  • [2024-02-27 20:24:20]
  • 提交

answer

/*
	failed
	debugging is painful
	but i don't know why
	perhaps, i need a more detailed solution (?)
*/

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

// #define Debug
// #define LOCAL

const int N = 800;

int n;
long long P;

long long inv[N + 5];

void init_inv()
{
	inv[1] = 1;
	for (int i = 2; i <= n; i++)
		inv[i] = (P - P / i) * inv[P % i] % P;
	return ;
}

long long f[N + 5][N + 5], g[N + 5];

void addto(long long &x, long long y)
{
	x = (x + y) % P;
	return ;
}

int main()
{
	#ifdef LOCAL
	freopen("data.in", "r", stdin);
	freopen("mycode.out", "w", stdout);
	#endif

	scanf("%d%lld", &n, &P);
	init_inv();

	f[1][0] = 1, g[1] = 1;
	for (int i = 2; i <= n; i++)
	{
		g[i] = f[i - 1][0] * inv[i] % P;

		for (int j = 0; j <= i; j++)
		{
			addto(f[i][j], f[i - 1][j + 1] * inv[i] % P);

			for (int k = 1; k <= i; k++)
			{
				addto(f[i][j], f[i - k][j] * g[k] % P * k % P * inv[i] % P);
				if (j > 0)
					addto(f[i][j], f[i - k][j - 1] * g[k] % P * (P - k) % P * inv[i] % P);
			}
		}

		#ifdef Debug
		cout << i << " legal = ";
		long long res = g[i];
		for (int t = 1; t <= i; t++)
			res = res * t % P;
		cout << res << endl;
		#endif
	}

	long long ans = g[n];1
	for (int i = 1; i <= n; i++)
		ans = ans * i % P;
	printf("%lld\n", ans);
	return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:75:31: error: expected ‘;’ before ‘for’
   75 |         long long ans = g[n];1
      |                               ^
      |                               ;
   76 |         for (int i = 1; i <= n; i++)
      |         ~~~                    
answer.code:76:25: error: ‘i’ was not declared in this scope
   76 |         for (int i = 1; i <= n; i++)
      |                         ^
answer.code:46:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   46 |         scanf("%d%lld", &n, &P);
      |         ~~~~~^~~~~~~~~~~~~~~~~~