【四校联考】棋盘
【题解】
显然的,黑色棋子怎么放是没有什么关系的,我们都可以通过交换行列使得黑色棋子在对角线上
这样的话,问题就转换为一个错排问题
错排问题公式:f[i]=(f[i-1]+f[i-2])*(i-1)
问题解决了
#include<stdio.h> #include<stdlib.h> #include<iostream> #include<string> #include<string.h> #include<algorithm> #include<math.h> #include<queue> #include<map> #include<vector> #include<set> #define il inline #define re register using namespace std; struct bignum{int len,s[1001]; } f[301]; int n; il bignum operator + (bignum a,bignum b){ bignum c; memset(c.s,0,sizeof(c.s)); c.len=max(a.len,b.len); for(int i=1;i<=c.len;i++){ c.s[i]+=a.s[i]+b.s[i]; c.s[i+1]+=c.s[i]/10; c.s[i]%=10; } if(c.s[c.len+1]>0) c.len++; return c; } il bignum operator * (bignum a,int b){ bignum c; memset(c.s,0,sizeof(c.s)); c.len=a.len; for(int i=1;i<=c.len;i++){ c.s[i]+=a.s[i]*b; c.s[i+1]+=c.s[i]/10; c.s[i]%=10; } while(c.s[c.len+1]>0){ c.len++; c.s[c.len+1]+=c.s[c.len]/10; c.s[c.len]%=10; } return c; } il void print(bignum a){ for(int i=a.len;i>=1;i--) printf("%d",a.s[i]); } int main(){ freopen("board.in","r",stdin); freopen("board.out","w",stdout); scanf("%d",&n); f[1].len=1; f[1].s[1]=0; f[2].len=1; f[2].s[1]=1; for(int i=3;i<=n;i++){ f[i]=(f[i-1]+f[i-2])*(i-1); } print(f[n]); return 0; }
蜉蝣渴望着飞翔,尽管黄昏将至