http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/3895.html
挺简单的一道题
不知道为什么去年那么多队这道题都过不了
你随便写写这不就是组合数吗
然后先打表阶乘
在用逆元
裸体啊
AC代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5,M=1e9+7;
ll JC[N+10];
ll T,w;
inline void read(ll &x){char ch;bool ok;
for(ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') ok=1;
for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok) x=-x;}
ll quickmod(ll a,ll b,ll m){
ll ans=1;
while(b){
if(b&1) ans=(ans*a)%m;
b>>=1;
a=a*a%m;
}
return ans;
}
ll inv(ll a,ll p){
return quickmod(a, p-2, p);
}
ll C(ll a,ll b,ll m){
return JC[a]*inv(JC[b],m)%m
*inv(JC[a-b],m)%m;
}
ll F(ll x,ll y){
ll a=abs(w-x);
if(a>T) return 0;
if(T&1){
if(a&1){
return y*C(T,T/2-a/2,M);
}
else{
return 0;
}
}
else{
if(a&1){
return 0;
}
else{
return y*C(T,T/2-a/2,M);
}
}
}
int main(){
ll n;
JC[0]=1;
for(ll i=1;i<=N;++i){
JC[i]=JC[i-1]*i%M;
}
while(cin>>n){
read(T),read(w);
ll ans=0;
while(n--){
ll a,b;
read(a),read(b);
ans+=F(a,b);
ans=ans%M;
}
printf("%lld\n",ans);
}
}
1万+

被折叠的 条评论
为什么被折叠?



