这个题相当于求从1-n的递增方案数,为C(2*n-1,n);

取模要用lucas定理,附上代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL mod=1000000007;
LL quick_mod(LL a,LL b){
	LL ans=1%mod;
	while(b){
		if(b&1){
			ans=ans*a%mod;
			b--;
		}
		b>>=1;
		a=a*a%mod; 
	}
	return ans;
} 
LL C(LL n,LL m){
	if(m>n)return 0;
	LL ans=1;
	for(int i=1;i<=m;i++){
		LL a=(n+i-m)%mod;
		LL b=i%mod;
		ans=ans*(a*quick_mod(b,mod-2)%mod)%mod;
	}
	return ans;
}
LL lucas(LL n,LL m){
	if(m==0)return 1;
	return C(n%mod,m%mod)*lucas(n/mod,m/mod)%mod;
}
int main(){
	LL a,ans;
	scanf("%lld",&a);
	ans=(2*lucas(a*2-1,a)%mod-a+mod)%mod;
	printf("%lld\n",ans);
} 

  

相关文章:

  • 2021-07-05
  • 2021-06-26
  • 2021-11-29
  • 2021-09-15
  • 2022-01-05
  • 2022-12-23
猜你喜欢
  • 2022-01-01
  • 2021-10-11
  • 2021-07-14
  • 2021-08-11
  • 2022-12-23
  • 2021-08-08
  • 2022-12-23
相关资源
相似解决方案