Hat's Fibonacci(杭电1250)

Hat‘s Fibonacci

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 7854    Accepted Submission(s): 2551

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
#include<stdio.h>
#include<string.h>
#define N 10000    //N很关键,N=10000或者20000都可以AC,N取得过小会错。
int str[N][260];
int main()
{
    memset(str,0,sizeof(str));
    str[1][0]=1;
    str[2][0]=1;
    str[3][0]=1;
    str[4][0]=1;
    int i,j,ans=0,c,n;
    for(i=5;i<N;i++)
    {
        for(j=0,c=0;j<260;j++)
        {
            ans=str[i-1][j]+str[i-2][j]+str[i-3][j]+str[i-4][j]+c;
            c=ans/100000000;
            str[i][j]=ans%100000000;   //每一个数组存8位数字,c来控制是否进位。
        }
    }
    while(scanf("%d",&n)!=EOF)
    {
        j=259;
        while(!str[n][j])    //将首0清除。
        j--;
        printf("%d",str[n][j]);
        for(i=j-1;i>=0;i--)
        printf("%08d",str[n][i]);//每8位输出,不足8位自动补0;
        printf("\n");
    }
    return 0;
}

Hat's Fibonacci(杭电1250)

时间: 2024-10-11 12:21:00

Hat's Fibonacci(杭电1250)的相关文章

Revenge of Fibonacci(杭电5018)

Revenge of Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 721    Accepted Submission(s): 332 Problem Description In mathematical terms, the sequence Fn of Fibonacci numbers is define

hdoj 1250 Hat&#39;s Fibonacci 【高精度】

Fibonacci... 策略:用Java 做这道题较简单一些,但是,C语言是基础. 用java的话,就是最简单的BigInteger的使用. 下面简单讲一下C语言的做法: 一个12位的整数,可以表示为,3个四位的整数的集合,例如123412341234就可以转化为1234, 1234, 1234.下面的就是按照此原理做的. c代码: #include <stdio.h>//每一个int都代表6个数. #include <string.h> #define M 10000 int

HDU 1250 Hat&#39;s Fibonacci(Java大数相加)+讲解

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1250 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 -

hdu 1250 Hat&#39;s Fibonacci

Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9677 Accepted Submission(s): 3210 Problem Description A Fibonacci sequence is calculated by adding the previous two members the seque

hdu 1250 Hat&#39;s Fibonacci(高精度数)

//  继续大数,哎.. 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 tas

HDOJ/HDU 1250 Hat&#39;s Fibonacci(大数~斐波拉契)

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

HDU 1250: Hat&#39;s Fibonacci

Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6925    Accepted Submission(s): 2279 Problem Description A Fibonacci sequence is calculated by adding the previous two members th

hdu 1250 Hat&#39;s Fibonacci (大数相加)

//a[n]=a[n-1]+a[n-2]+a[n-3]+a[n-4]; # include <stdio.h> # include <algorithm> # include <string.h> # include <iostream> using namespace std; int a[10000][260]={0}; //每个元素可以存储8位数字,所以2005位可以用260个数组元素存储. int main() { int i,j,n; a[1][0

HDUJ 1250 Hat&#39;s Fibonacci

Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7338    Accepted Submission(s): 2395 Problem Description A Fibonacci sequence is calculated by adding the previous two members th