BZOJ4563 HAOI2016放棋子(高精度)

  没看清题还以为是要求数最大匹配数量……注意到任意障碍不在同一行同一列,且恰好有n个障碍,不妨通过交换列使得第i行第i列均有障碍。那么就是个错排了。居然wa了一发简直没救。

#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 210
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int n,f[N][N<<2];
int main()
{
#ifndef ONLINE_JUDGE
    freopen("bzoj4563.in","r",stdin);
    freopen("bzoj4563.out","w",stdout);
    const char LL[]="%I64d\n";
#else
    const char LL[]="%lld\n";
#endif
    n=read();
    f[0][1]=1;f[0][0]=f[1][0]=1;
    for (int i=2;i<=n;i++)
    {
        f[i][0]=f[i-1][0];
        for (int j=1;j<=f[i][0];j++)
        {
            f[i][j]+=f[i-1][j]+f[i-2][j];
            if (f[i][j]>9) f[i][j+1]++,f[i][j]-=10;
        }
        if (f[i][f[i][0]+1]) f[i][0]++;
        for (int j=1;j<=f[i][0];j++)
        f[i][j]*=i-1;
        for (int j=1;j<=f[i][0];j++)
        f[i][j+1]+=f[i][j]/10,f[i][j]%=10;
        while (f[i][f[i][0]+1]) f[i][0]++,f[i][f[i][0]+1]+=f[i][f[i][0]]/10,f[i][f[i][0]]%=10;
    }
    for (int i=f[n][0];i>=1;i--) cout<<f[n][i];
    return 0;
}

 

posted @ 2018-11-01 01:27  Gloid  阅读(153)  评论(0编辑  收藏  举报