HDU 4869 Turn the pokers

/*
HDU4869
http://acm.hdu.edu.cn/showproblem.php?pid=4869
费马小定理+快速幂 求逆元 暴力组合数
奇偶性
*/
#include <cstdio>
#include <algorithm>
using namespace std;
const __int64 Nmax=100005LL;
const __int64 mod=1000000009LL;
__int64 fac[Nmax];//i!
__int64 l,r,n,m;
void get()
{
    fac[0]=fac[1]=1LL;
    for(__int64 i=2LL;i<=Nmax-1;i++)
        fac[i]=(fac[i-1]*(i%mod))%mod;
}

__int64 pow(__int64 base,__int64 n)
{
    __int64 ans=1LL;
    base=base%mod;
    while(n>0LL)
    {
        if(n&1LL)
            ans=(ans*base)%mod;
        base=(base*base)%mod;
        n>>=1;
    }
    return ans;
}

__int64 C(__int64 n,__int64 m)
{
    __int64 ans=1LL;
    ans=fac[n]%mod;
    ans=(ans* (pow(fac[m]*fac[n-m],mod-2)%mod) )%mod;
    // ans=(ans* (pow(fac[m],mod-2)%mod))%mod;
    // ans=(ans* (pow(fac[n-m],mod-2)%mod))%mod;
    return ans;
}

void get_limit()
{
    l=r=0LL;
    int x;
    for(int i=1;i<=m;i++)
    {
        scanf("%d",&x);
        __int64 ll,rr;
        //1->0
        if(x<=l)//  x  l  r
            ll=l-x;
        else if(x<=r)// l  x  r  
        {
            if((x&1)==(l&1))
                ll=0;
            else
                ll=1;
        }    
        else// l  r  x
            ll=x-r;

        //0->1
        if(r+x<=n) 
            rr= r+x;//
                else if(l+x<=n)
                {
                    if(((l+x)&1) == (n&1))
                        rr=n;
                    else
                        rr=n-1;
                }
                else 
                    rr = 2*n-(l+x);//
                l=ll,r=rr;
    }
}

int main()
{
    //freopen("HDU4869.in","r",stdin);
    get();
    while(scanf("%I64d%I64d",&m,&n)==2)
    {
        get_limit();
        __int64 ans=0LL;
        // printf("%d %d\n",l,r);
        for(__int64 i=l;i<=r;i+=2)
        {
            ans=(ans+C(n,i)%mod);
            // printf("C(%I64d,%d)=%I64d\n",n,i,C(n,i));
        }
        ans%=mod;
        while(ans<0)
            ans+=mod;
        printf("%I64d\n",ans);    
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/BBBob/p/6522903.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值