题目链接
Sample Input
4 5
Sample Output
10
Source
2016"百度之星" - 初赛(Astar Round2B)
#include<bits/stdc++.h>
using namespace std;
const int maxn =2e5+500;
const int mod=1e9+7;
typedef long long ll;
ll f[maxn],inv[maxn];
ll quick(ll a,ll b){
ll ans=1;
a=a%mod;
while(b!=0){
if(b&1) ans=(ans*a)%mod;
b>>=1;
a=(a*a)%mod;
}
return ans;
}
ll slove(int n,int m)
{
if(m>n) return 0;
return f[n]*inv[m]%mod*inv[n-m]%mod;
}
int main()
{
int n,m;
f[0]=inv[0]=1;
for(int i=1;i<maxn;++i)
f[i]=f[i-1]*i%mod,inv[i]=quick(f[i],mod-2)%mod;
while(scanf("%d %d",&n,&m)!=EOF){
printf("%lld\n",slove(n+m-4,m-2));
}
}