Loading

代码-SDOI2011 黑白棋

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define x first
#define y second
#define bg begin()
#define ed end()
#define pb push_back
#define mp make_pair
#define sz(a) int((a).size())
#define R(i,n) for(int i(0);i<(n);++i)
#define L(i,n) for(int i((n)-1);i>=0;--i)
const int iinf=0x3f3f3f3f;
const ll linf=0x3f3f3f3f3f3f3f3f;

//Data
const int N=1e4+1,B=15;
int n,m,d,f[2][N];

//Math
const int mod=1e9+7;
void fmod(int &x){x+=x>>31&mod;}
int Pow(int a,int x,int res=1){
    for(;x;x>>=1,a=1ll*a*a%mod)
        (x&1)&&(res=1ll*res*a%mod);
    return res;
}
int fac[N],ifac[N];
void init(){
    fac[0]=1;
    R(i,n) fac[i+1]=1ll*fac[i]*(i+1)%mod;
    ifac[n]=Pow(fac[n],mod-2);
    L(i,n) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
}
int c(int a,int b){
    if(b<0||b>a||a<0) return 0;
    return 1ll*fac[a]*ifac[b]%mod*ifac[a-b]%mod;
}

//Main
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n>>m>>d,init(),n-=m,m/=2;
    int now=0;
    f[now][0]=1;
    R(b,B){
        R(i,n+1) f[now^1][i]=0;
        R(i,n+1)if(f[now][i])
            for(int j=0;j<=m&&i+j*(1<<b)<=n;j+=d+1)
                fmod(f[now^1][i+j*(1<<b)]+=1ll*c(m,j)*f[now][i]%mod-mod);
        now^=1;
    }
    int ns=c(n+2*m,2*m);
    R(i,n+1) fmod(ns-=1ll*f[now][i]*c(n-i+m,m)%mod);
    cout<<ns<<'\n';
    return 0;
}
posted @ 2020-11-27 11:39  George1123  阅读(57)  评论(0编辑  收藏  举报