“浪潮杯”山东省第八届ACM大学生程序设计竞赛fireworks (组合数)

坑的一笔,用lucas生成组合数,老是错,后来看别人都用逆元生成,就用了逆元,发现逆元确实快的惊人。还是没认真思考复杂度,看到lucas就想套模板,根本没去想复杂度。

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int mod = 1e9+7;
typedef unsigned long long LL;
LL jie[110000];

void init()
{
    jie[0]=jie[1]=1;
    for(int i=2; i<=100000; i++)
        jie[i]=(jie[i-1]*i)%mod;
}

LL mult(LL a,LL n)
{
    LL ans=1;
    while(n)
    {
        if(n&1)ans=(ans*a)%mod;
        a=(a*a)%mod;
        n>>=1;
    }
    return ans;
}

LL C(LL n,LL m)
{
    return ((jie[n]*mult(jie[n-m],mod-2))%mod*mult(jie[m],mod-2))%mod;
}

int x,val;
int main()
{
    init();
 int n,t,w;
 while(~scanf("%d%d%d",&n,&t,&w))
 {
     LL ans=0;

     for(int i=1;i<=n;i++)
     {
         scanf("%d%d",&x,&val);
         x-=t;
         if(w<x)continue;
         int tmp=w-x;
         if(tmp%2)continue;
         tmp/=2;
         if(tmp>t)continue;
         //cout<<tmp<<endl;
         if(tmp*2>t)
            tmp=t-tmp;
         ans+=C(t,tmp)*val;
         ans%=mod;
     }
    printf("%lld\n",ans);
 }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/clx55555/article/details/80070291