具有相同元素的排列组合模板

const int mod=1e9+7;
typedef long long ll;
//返回d=gcd(a,b);和对应于等式ax+by=d中的x,y
ll extend_gcd(ll a,ll b,ll &x,ll &y)
{
    if(a==0&&b==0) return -1;//无最大公约数
    if(b==0){x=1;y=0;return a;}
    ll d=extend_gcd(b,a%b,y,x);
    y-=a/b*x;
    return d;
}
//*********求逆元素*******************
//ax = 1(mod n)
ll mod_reverse(ll a,ll n)
{
    ll x,y;
    ll d=extend_gcd(a,n,x,y);
    if(d==1) return (x%n+n)%n;
    else return -1;
}

ll c(ll m,ll n)
{
    ll i,j,t1,t2,ans;
    t1=t2=1;
    for(i=n;i>=n-m+1;i--) t1=t1*i%mod;
    for(i=1;i<=m;i++) t2=t2*i%mod;
    return  t1*mod_reverse(t2,mod)%mod;
}
原文地址:https://www.cnblogs.com/pshw/p/5323988.html