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.

#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std; const int INF=1e9+7;
const int maxn=2010; int a[10000][260]= {0}; //每个元素可以存储8位数字,所以2005位可以用260个数组元素存储。
int main()
{
int i,j,n;
a[1][0]=1; //赋初值
a[2][0]=1;
a[3][0]=1;
a[4][0]=1;
for(i=5; i<10000; i++)
{
for(j=0; j<260; j++)
a[i][j]+=a[i-1][j]+a[i-2][j]+a[i-3][j]+a[i-4][j];
for(j=0; j<260; j++) //每八位考虑进位。
if(a[i][j]>100000000)
{
a[i][j+1]+=a[i][j]/100000000;
a[i][j]=a[i][j]%100000000;
}
}
while(scanf("%d",&n)!=EOF)
{
for(j=259; j>=0; j--)
if(a[n][j]!=0) break; //不输出高位的0
printf("%d",a[n][j]);
for(j=j-1; j>=0; j--)
printf("%08d",a[n][j]); //每个元素存储了八位数字,所以控制输出位数为8,左边补0
printf("\n");
}
return 0;
}

Hat's Fibonacci hdu 1250的更多相关文章

  1. hdu 1250 Hat's Fibonacci

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1250 Hat's Fibonacci Description A Fibonacci sequence ...

  2. HDU 1250 Hat's Fibonacci(大数相加)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1250 Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Ot ...

  3. hdu 1250 Hat&#39;s Fibonacci

    pid=1250">点击此处就可以传送hdu 1250 Problem Description A Fibonacci sequence is calculated by adding ...

  4. HDU 1250 Hat's Fibonacci (递推、大数加法、string)

    Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  5. Hat's Fibonacci(大数加法+直接暴力)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1250 hdu1250: Hat's Fibonacci Time Limit: 2000/1000 M ...

  6. HDUOJ----1250 Hat's Fibonacci

    Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  7. Hat's Fibonacci(大数,好)

    Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  8. (二维数组 亿进制 或 滚动数组) Hat's Fibonacci hdu1250

    Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. hdu 1250(大整数)

    Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

随机推荐

  1. ACM选修HUST1058(市赛题) Lucky Sequence 同余定理

    Description Edward  得到了一个长度为  N  的整数序列,他想找出这里面有多少个“幸运的”连续子序列.一个连续子序列被称为“幸运的”,当且仅当该子序列内的整数之和恰好是  K  的 ...

  2. C11工具类:字符转换

    1.数值类型和字符串转换 1.1 数值转换为字符 std::string to_string(int value); std::string to_string(long value); std::s ...

  3. python中拷贝对象的区别

    一.赋值.引用 在python中赋值语句总是建立对象的引用值,而不是复制对象.因此,python变量更像是指针,而不是数据存储区域 这点和大多数语音类似吧,比如C++.Java等 1.先看个例子: v ...

  4. 集合框架小结-List

    List集合存储的元素是有序的,可重复的,有索引 List特有方法: 增加 add(index, element); addAll(index, Collection); 删除 remove(inde ...

  5. 【Git/GitHub学习笔记】一键更新多个git仓库至远程

    因为同时在本地维护几个Github的仓库,每次更新后每个仓库要重复三步提交同步,有点麻烦. 发现可以写.sh文件来实现一键更新. 比如我要更新我的BlogBackup和CodeRepo两个仓库的代码如 ...

  6. 多播知识by 陈胜君

    简单的讲一下多拨的说明:一.多拨分物理多拨和虚拟多拨. 物理多拨是电信老套餐,就是一个宽带支持四个内网设备同时拨号上网,即2004年以前,允许家里四台电脑直接连LAN网口启动拨号,同时允许四拨在线.现 ...

  7. Tutorial 2: Requests and Responses

    转载自:http://www.django-rest-framework.org/tutorial/2-requests-and-responses/ Tutorial 2: Requests and ...

  8. substring() slice() substr()的区别联系

    例如:var str='q1207526854' str.substring(form,to):从字符串里截取下标为form到下标为to的字符串(不包括to对应的字符)alert(str.substr ...

  9. centos6.5 使用 rpm 安装 mysql

    从mysql网站下载mysql rpm安装包(包括server.client) 1.安装server rpm -ivh MySQL-server-5.6.19-1.el6.x86_64.rpm 强制安 ...

  10. 域名 DNS命令——dig

    dig命令详解   1.查看域名的A记录          # dig yahoo.com; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.e ...