8 . 6

T1T1 calculator

#include<bits/stdc++.h>
using namespace std;
int rd()
{
	int x=0,fg=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')fg=-fg;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return fg*x;
}
typedef long long ll;
const int M=1e9+7;
const int N=200000;
int s,t,k;
ll f1[N],f2[N];
ll qpow(ll x,int y){
	ll tmp=x,res=1;
	while(y){
		if(y&1) res=(res*tmp)%M;
		tmp=(tmp*tmp)%M;
		y>>=1;
	}
	return res;
}
void prepare(){
	f1[0]=1;
	for(int i=1;i<=N;++i) f1[i]=(ll)f1[i-1]*(ll)i%M;
	f2[N]=qpow(f1[N],M-2);
	for(int i=N-1;i>=0;--i) f2[i]=(ll)f2[i+1]*(ll)(i+1)%M;
}
ll c(int n,int r){
	return (ll)f1[n]*f2[r]%M*f2[n-r]%M;
}
/* 60p
void work1(){
	memset(f,0,sizeof(f));
	f[s+1][1]=1; 
	for(int i=s+1;i<=s+k+1;++i)
		for(int j=1;j<=s+k-i+2;++j){  
			if(f[i][j]) continue;
			if(j>i) break;
			f[i][j]=(f[i][j-1]+f[i-1][j])%M;
	        if(i-j==t) ans=(ans+f[i][j])%M;
		}
	printf("%lld\n",ans);
	return;
}
*/
int main()
{
	freopen("calculator.in", "r", stdin);
	freopen("calculator.out", "w", stdout);	
	s=rd(); t=rd(); k=rd();
	prepare();
	ll ans=0;
	if(s>t) swap(s,t);
	for(int i=0;i<=k;++i){
		if((i+t-s)&1) continue;
		int x=(i-t+s)>>1,y=(i+t-s)>>1;
		if(x<0) continue;
		(ans+=c(x+y,x))%=M;
		if(x>s)
		(ans+=(M-c(x+y,x-s-1)))%=M;
	}
	printf("%lld\n",ans%M);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值