A Path Plan(LGV定理 多条路径不相交方案数)

原题: 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 aibi且路径不相交的方案数为下面行列式的值。
在这里插入图片描述

而此题中 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 );
    }
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值