【HAOI2016】放棋子

题面

题解

任意两个障碍不在同一列

要求你放$N$个棋子也满足每行只有一枚棋子,每列只有一枚棋子的限制。

这™不就是个错排吗???

$$ h_i=(n-1)(h_{i-1}+h_{i-2}),h_1=0,h_2=1 $$

写个高精度就好了。。。

代码

#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define RG register

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while(ch != '-' && (!isdigit(ch))) ch = getchar();
	if(ch == '-') w = -1, ch = getchar();
	while(isdigit(ch)) data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int maxn(210), Mod(1e8);
int n, a[maxn];
long long f[maxn][50];

int main()
{
	n = read(); f[1][0] = 0, f[2][0] = 1;
	for(RG int i = 3; i <= n; i++)
	{
		for(RG int j = 0; j <= a[i - 1]; j++)
			f[i][j] = f[i - 1][j] + f[i - 2][j];
		a[i] = a[i - 1];
		for(RG int j = 0; j <= a[i - 1]; j++)
			f[i][j + 1] += f[i][j] / Mod,
			f[i][j] %= Mod;
		while(f[i][a[i] + 1]) ++a[i];
		for(RG int j = 0; j <= a[i]; j++) f[i][j] *= i - 1;
		for(RG int j = 0; j <= a[i]; j++)
			f[i][j + 1] += f[i][j] / Mod,
			f[i][j] %= Mod;
		while(f[i][a[i] + 1]) ++a[i];
	}
	printf("%lld", f[n][a[n]]);
	for(RG int i = a[n] - 1; ~i; i--) printf("%08lld", f[n][i]);
	return 0;
}
posted @ 2019-01-09 21:09  xgzc  阅读(178)  评论(0编辑  收藏  举报