• 【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;
    }
    
  • 相关阅读:
    Codeforces 937D
    Codeforces 458C
    Codeforces 934D
    Codeforces 934C
    Codeforces 36B
    Codeforces 374C
    Codeforces 374D
    编译优化
    Codeforces E
    Codeforces 920G
  • 原文地址:https://www.cnblogs.com/cj-xxz/p/10246876.html
Copyright © 2020-2023  润新知