Hat's Fibonacci

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5800    Accepted Submission(s): 1926

Problem Description
A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1.
F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n - 1) + F(n-2) + F(n-3) + F(n-4)
Your task is to take a number as input, and print that Fibonacci number.
 
Input
Each line will contain an integers. Process to end of file.
 
Output
For each case, output the result in a line.
 
Sample Input
100
 
Sample Output
4203968145672990846840663646 Note: No generated Fibonacci number in excess of 2005 digits will be in the test data, ie. F(20) = 66526 has 5 digits.
 
Author
戴帽子的
 
Recommend
Ignatius.L
 
 大数题,我先是用打表的方法,发现数字到达7037的时候,数字规模才能达到2005 ...然后用7037*2005 ---->已经超过内存,所以这条路实不可取的。。。唯一的方法,只好暴力法,但又担心会超时,可是,喜感就是,竟然过了,还应458ms。。。。哎!!!。
贴下代码:
   #include<stdio.h>
#include<string.h>
#define maxn 2006
int a[maxn],b[maxn],c[maxn],d[maxn],ans[maxn];
int main()
{
int i,j,e,s,up,num;
while(scanf("%d",&num)!=EOF)
{
if(num<=)
printf("");
else
{
memset(a,,sizeof a);
memset(b,,sizeof b);
memset(c,,sizeof c);
memset(d,,sizeof d);
memset(ans,,sizeof ans);
a[]=b[]=c[]=d[]=;
for(i=,up=;i<num;i++)
{
for(j=,e=;j<=up;j++)
{
s=a[j]+b[j]+c[j]+d[j]+e;
ans[j]=s%;
e=(s-ans[j])/;
if(s>&&j==up) up++;
a[j]=b[j];
b[j]=c[j];
c[j]=d[j];
d[j]=ans[j];
}
}
for(j=maxn;ans[j]==;j--);
for(i=j;i>=;i--)
{
printf("%d",ans[i]);
}
}
printf("\n");
}
return ;
}

最新文章

  1. caffe 基本知识简介
  2. 综合使用spring cloud技术实现微服务应用
  3. ffmpeg-20160629-git-bin.7z
  4. CentOS版本选择说明
  5. JavaScript设计模式——状态模式
  6. supersocket+controller+action
  7. 浅谈session/cookie
  8. android: SQLite创建数据库
  9. 【软件使用】Windows下的Objective-C集成开发环境搭建(IDE)
  10. java类总结
  11. hibernate工具类HibernateUtil详解
  12. 李洪强漫谈iOS开发[C语言-037]-if else 语句
  13. warden 的设计与实现 总结
  14. Js弹性漂浮广告代码
  15. opencart添加任意页面到导航栏(修改一级菜单)
  16. 201521123029《Java程序设计》第九周学习总结
  17. mysql服务设置远程连接 解决1251 client does not support ..问题
  18. css at @ 规则
  19. ps遇到的技术问题列表
  20. Albert Einstein

热门文章

  1. 对JVM还一知半解
  2. dubbo培训文档
  3. e为无理数的证明
  4. 转: Source Code Lookup in Eclipse(主要讲的是java的)
  5. 通过page页面与portlet的结合实现报表的局部刷新
  6. 微信小程序开发及相关设置小结
  7. [Functional Programming] Fst &amp; Snd, Code interview question
  8. 【leetcode 桶排序】Maximum Gap
  9. 【Python】在控制台输出不同颜色的文字
  10. ArcGIS安装问题集锦