51nod 1119【杨辉三角】

思路:
= =杨辉三角的应用,组合数的应用;
C(N+M,N);
逆元一发,费马小定理,OK。

#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;

typedef long long LL;

const LL mod=1e9+7;

LL cal(LL g,LL x)
{
    LL ans=1;
    while(g)
    {
        if(g%2)
            ans=(ans*x)%mod;
        x=(x*x)%mod;
        g>>=1;
    }
    return ans;
}
//C(N+M,N);
/*
(N+M)!
------
N!*M!
*/
LL dp[2000010];
void Init()
{
    dp[1]=1;
    for(LL i=2;i<=2000010;i++)
        dp[i]=(dp[i-1]*i)%mod;
}
int main()
{
    LL n,m;
    Init();
    scanf("%lld%lld",&m,&n);
    LL ans;
    ans=dp[n+m-2]*cal(mod-2,dp[n-1])%mod*cal(mod-2,dp[m-1])%mod;
    printf("%lld",ans);
    return 0;
}

原文地址:https://www.cnblogs.com/keyboarder-zsq/p/5934832.html