http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3688
组合数学题,牵涉到禁位问题,棋牌多项式,把禁位标记在棋盘上,我们要算出有i个棋子在禁位上面的方案数,这个可以用组合数学求。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <queue>
#include <map>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cctype>
#include <set>
#include <cmath>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAXN=2e5+10;
ll f[MAXN];
ll mod_pow(ll a,ll n)
{
ll ans=1;
while(n)
{
if(n&1) ans=ans*a%MOD;
a=a*a%MOD;
n>>=1;
}
return ans;
}
int main()
{
//freopen("in","r",stdin);
f[0]=1;
for(int i=1;i<MAXN;i++) f[i]=f[i-1]*i%MOD;
int n;
while(cin>>n)
{
ll ans=f[n];
for(int i=1;i<=n;i++)
{
ll v=f[2*n-i-1]*mod_pow(f[i-1],MOD-2)%MOD;
v=v*mod_pow(f[2*n-2*i],MOD-2)%MOD;
v=v*2*n%MOD;
v=v*mod_pow(i,MOD-2)%MOD;
v=v*f[n-i]%MOD;
if(i%2==0) ans=(ans+v)%MOD;
else ans=(ans-v+MOD)%MOD;
}
if(n==1) ans=0;
cout<<ans<<endl;
}
return 0;
}