原题: http://acm.hdu.edu.cn/showproblem.php?pid=6482
题意:
两个人在y轴上,他们的家在x轴上,问两个人到家的路径没有重复点的方案数(只能往右下走)。
LGV定理:
设
e
(
a
i
,
b
j
)
e(a_i,b_j)
e(ai,bj)为点
a
i
a_i
ai到达
b
j
b_j
bj的方案数,那么所有
a
i
→
b
i
a_i\to b_i
ai→bi且路径不相交的方案数为下面行列式的值。
而此题中 e ( a 1 , b 1 ) = C x + y y e(a_1,b_1)=C_{x+y}^y e(a1,b1)=Cx+yy,n=2直接做就行。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=3e5+5;
const LL mod=1e9+7;
LL fac[maxn],inv_fac[maxn];
LL Pow(LL a,LL b){
LL ans=1;
while(b){
if(b&1)ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
void init(){
fac[0]=1;
for(int i=1;i<maxn;i++)fac[i]=fac[i-1]*i%mod;
inv_fac[maxn-1]=Pow(fac[maxn-1],mod-2);
for(int i=maxn-2;i>=0;i--){
inv_fac[i]=inv_fac[i+1]*(i+1)%mod;
}
}
LL C(LL a,LL b){
return fac[a]*inv_fac[b]%mod*inv_fac[a-b]%mod;
}
int main(){
init();
int t;scanf("%d",&t);
while(t--){
LL x,xx,y,yy;
scanf("%lld%lld%lld%lld",&x,&xx,&y,&yy);
LL ans[4];
ans[0]=C(x+y,y);
ans[1]=C(xx+y,y);
ans[2]=C(x+yy,yy);
ans[3]=C(xx+yy,yy);
printf("%lld\n",((ans[0]*ans[3]-ans[1]*ans[2])%mod+mod)%mod );
}
}