题目大意:

\(F(x) = 1 (0 \leq x < 4)\)

\(F(x) = F(x-1) + F(x-\pi) (4 \leq x)\)

给定\(n\),求\(F(n)\)

题解:

我们把所有的数表示为\(a - b*\pi\)

然后把所有的二元对\((a,b)\)映射到坐标。

我们发现递归求解时经过的所有的边和映射出来的点构成了一张网格图。

所以我们直接应用组合数进行方案数计算即可.

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
const int mod = 1e9+7;
const double pi = acos(-1);
int fac[1200010],inv[1200010];
inline int qpow(int x,int p){
int ret = 1;
for(;p;p>>=1,x=1LL*x*x % mod) if(p&1) ret=1LL*ret*x % mod;
return ret;
}
inline void pre(){
int n = 1000010;
fac[0] = 1;
for(int i=1;i<=n;++i) fac[i] = 1LL*i*fac[i-1] % mod;
inv[n] = qpow(fac[n],mod-2);
for(int i=n-1;i>=0;--i) inv[i] = 1LL*inv[i+1]*(i+1) % mod;
}
inline int C(int n,int m){
if(n < m) return 0;
return 1LL*fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main(){
pre();
int num;read(num);
int n = 3,m = 0,ans = 0;
if(num < 4) return puts("1");
for(;n <= num;++n){
if(n - m*pi >= 4){
ans += C(num-n+m,m)*2 % mod;
++ m;
}else if(m > 0) ans += C(num-n+m-1,m-1);
if(ans >= mod) ans -= mod;
}
printf("%d\n",ans);
return 0;
}

最新文章

  1. php实现文件上传与下载(上)
  2. 转,SelectNodes + XPath
  3. webAPI 数组参数
  4. js关闭当前页面(窗口)的几种方式总结(转)
  5. [AaronYang]C#人爱学不学[7]
  6. 使用NSURLSession实现断点续传
  7. Redshift扩容及踩到的坑
  8. Java十二周总结
  9. python基础——抽象类
  10. Spring Boot自定义Banner
  11. 8_管理及IO重定向
  12. 在数据库中sql查询很快,但在程序中查询较慢的解决方法
  13. 个人实验 github地址:https://github.com/quchengyu/cher
  14. [LeetCode] 455. Assign Cookies_Easy tag: Sort
  15. IE的“浏览器模式”和“文档模式的区别”
  16. Android-Failed to open zip file
  17. Ubuntu中开启和关闭防火墙-摘自网络
  18. supervisord管理进程详解
  19. gitHub 迁移到gitlab上
  20. 网络I/O虚拟化,SR-IOV技术

热门文章

  1. 【BZOJ2530】[Poi2011]Party (xia)构造
  2. node.js实现国标GB28181设备接入的sip服务器解决方案
  3. iOS11 push控制器tabbar上移问题
  4. [ZJOI2006]三色二叉树
  5. (3)mac下&quot;-bash: mysql: command not found&quot;解决方案
  6. activiti基础--2----------------------(流程定义)
  7. swap 内存不足
  8. 11.2.3 Redis的启动停止
  9. 波浪分析数据转换:大智慧、钱龙、胜龙可用Advanced GET ToGet 数据转换器V3.05特别版
  10. Android selector背景选择器