这个题需要自己模拟,然后就能看出是杨辉三角.
当然不能直接数组打表,也不能Lucas,逆元求组合数
具体解法解释请看链接组合数取模(sdut3895+HDU3037)逆元法或Lucas
如果T%2==|w-xi|%2
result+=ci*C(T/2-dis/2,T)
#include<cstdio>
#include<iostream>
using namespace std;
#define ll long long
const int mod=1000000007;
const int maxn=100010;
ll jiecheng[maxn];
ll quzheng(ll a,ll b)
{
return a>b?a-b:b-a;
}
ll kuaisumi(ll a,ll b)
{
ll ans=1;
while(b)
{
if(b&1)
{
b--;
ans=(ans*a)%mod;
}
b=b>>1;
a=(a*a)%mod;
}
ans=ans%mod;
return ans;
}
ll C(ll m,ll n)
{
if(m>n)
return 0;
ll M=kuaisumi(jiecheng[m],mod-2);
ll NM=kuaisumi(jiecheng[n-m],mod-2);
return (((jiecheng[n]*M)%mod*NM)%mod)%mod;
}
int main()
{
jiecheng[0]=1;jiecheng[1]=1;
for(int i=2;i<maxn;i++)
{
jiecheng[i]=jiecheng[i-1]*i%mod;
}
ll n,T,w;
while(cin>>n>>T>>w)
{
ll flag=T%2;
ll res=0;
while(n--)
{
ll x,c;
cin>>x>>c;
ll dis=quzheng(w,x);
if(dis%2==flag&&dis<=T)
{
res+=(c*C(quzheng(T/2,dis/2),T)%mod);
res=res%mod;
}
}
res=res%mod;
cout<<res<<endl;
}
return 0;
}