zoj 3688

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值