#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<map>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll maxn=2*1e5+5;
ll fact[maxn],f[maxn];
ll quick_mod(ll a,ll k)
{
ll res=1;
while(k)
{
if(k&1)
res=res*a%mod;
a=a*a%mod;
k>>=1;
}
return res;
}
void init()
{
fact[0]=1;
f[0]=1;
for(int i=1;i<maxn;i++)
fact[i]=fact[i-1]*i%mod;
for(int i=1;i<maxn;i++)
f[i]=quick_mod(fact[i],mod-2);
}
ll solve(ll n,ll m)
{
return fact[n]*f[m]%mod*f[n-m]%mod;
}
int main()
{
init();
ll n,m,i,j,res;
while(scanf("%lld%lld",&n,&m)!=EOF)
{
n-=min(n,m);
m--;
res=0;
ll minn=min(n,m);
for(i=0;i<=minn;i++)
res=(res+solve(n+m-i,i)*solve(n+m-2*i,n-i))%mod;
printf("%lld\n",res);
}
return 0;
}
山东省第八届acm省赛D题HEX(组合数学)
最新推荐文章于 2018-07-17 12:58:25 发布