51nod1149 Pi的递推式 组合数学

Description


定义 f ( x ) = { 1 ,    x ∈ [ 0 , 4 ) f ( x − 1 ) + f ( x − π ) ,    x ∈ [ 0 , + ∞ ) f(x)=\left\{ \begin{aligned} 1,\;&x\in[0,4)\\ f(x-1)+f(x-\pi),\;&x\in[0,+\infty)\\ \end{aligned} \right. f(x)={1,f(x1)+f(xπ),x[0,4)x[0,+)
f ( n ) f(n) f(n)

Solution


相当于一次可以走一步,可以走 π \pi π步,问从0走到 ( n − 4 , n ] (n-4,n] (n4,n]有几种走法
我们枚举走了1步的次数,枚举走了 π \pi π步的步数,组合数算就可以了

Code


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#define rep(i,st,ed) for (int i=st;i<=ed;++i)

typedef long long LL;
const double pi=acos(-1);
const int MOD=1000000007;
const int N=2000005;

LL fac[N],ny[N];

int f(double x) {
	if (x>=0&&x<4) return 1;
	return (f(x-1)+f(x-pi))%MOD;
}

LL C(int n,int m) {
	if (n<m) return 0;
	return fac[n]*ny[m]%MOD*ny[n-m]%MOD;
}

LL ksm(LL x,LL dep) {
	LL res=1;
	for (;dep;dep>>=1) {
		(dep&1)?(res=res*x%MOD):0;
		x=x*x%MOD;
	}
	return res;
}

int main(void) {
	fac[0]=1; rep(i,1,N-1) fac[i]=fac[i-1]*i%MOD;
	rep(i,0,N-1) ny[i]=ksm(fac[i],MOD-2);
	int n; scanf("%d",&n);
	if (n<4) return 0&puts("1");
	LL ans=0;
	rep(i,0,n-4) {
		int tmp=(n-i-4)/pi;
		ans=(ans+C(tmp+i,i))%MOD;
	}
	rep(i,0,n-4) if (i*pi<=n-4) {
		int tmp=(int)(n-4-pi*i);
		ans=(ans+C(tmp+i,i))%MOD;
	}
	printf("%lld\n", ans);
	printf("%d\n", f(n));
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值