51nod_1627:瞬间移动

时间:2023-12-18 17:21:44

题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1627

还是杨辉三角~

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

;
const LL M=2e5;
LL fac[M+];               //阶乘
LL inv_of_fac[M+];        //阶乘的逆元
LL qpow(LL x,LL n)
{
    LL ret=;
    )
    {
        ) ret=ret*x%mod;
        x=x*x%mod;
    }
    return ret;
}
void init()
{
    fac[]=;
    ; i<=M; i++)
        fac[i]=fac[i-]*i%mod;
    inv_of_fac[M]=qpow(fac[M],mod-);
    ; i>=; i--)
        inv_of_fac[i]=inv_of_fac[i+]*(i+)%mod;
}
LL C(LL a,LL b)
{
    ||a<b) ;
    return fac[a]*inv_of_fac[b]%mod*inv_of_fac[a-b]%mod;
}

int main()
{
    init();
    int n,m;
    while(cin>>n>>m)
    {
        n--;m--;
        if(n<m) swap(n,m);
        cout<<C(n+m-,m-)<<endl;
    }
}