# [BZOJ4005][JLOI2015]骗我呢-[dp+容斥]

## Code

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int n,m;
ll fac[12000010],inv[12000010];
void pre()
{
fac[0]=inv[0]=1;
fac[1]=inv[1]=1;
for (int i=2;i<=12000000;i++)
{
fac[i]=fac[i-1]*i%mod;
inv[i]=(mod-mod/i)*inv[mod%i]%mod;
}
for (int i=1;i<=12000000;i++) inv[i]=inv[i]*inv[i-1]%mod;
}
ll C(int x,int y)
{
if (x<y||x<0||y<0) return 0;
return fac[x]*inv[y]%mod*inv[x-y]%mod;
}
ll cal(int x,int y)
{
if (x<0||y<0) return 0;return C(x+y,y);
}
void turnA(int &x,int &y)
{
swap(x,y);
x--;y++;
}
void turnB(int &x,int &y)
{
swap(x,y);x+=m+2;y-=m+2;
}
ll ans;
int main()
{
scanf("%d%d",&n,&m);
pre();
ans=cal(n+m+1,n);
int x=n+m+1,y=n;
while (x>=0&&y>=0)
{
turnA(x,y);ans=(ans-cal(x,y))%mod;
turnB(x,y);ans=(ans+cal(x,y))%mod;
}
x=n+m+1,y=n;
while (x>=0&&y>=0)
{
turnB(x,y);ans=(ans-cal(x,y))%mod;
turnA(x,y);ans=(ans+cal(x,y))%mod;
}
if (ans<0) ans+=mod;
cout<<ans;
}

posted @ 2018-08-29 12:20  _雨后阳光  阅读(810)  评论(0编辑  收藏  举报