Two or three things about ZZULIOJ1091 's childhood, Fibonacci, math.

Source: Internet
Author: User
1091: The childhood life two or three things (multi-instance test)Time limit:1 Sec Memory limit:128 MB
submit:4299 solved:2457

Submit Status Web Board Description

Redraiment like to bounce when he was a child, and he likes to jump up and down the stairs.
But at a young age, he can only go one step at a time or jump on two.
There are now a total of N-step, please calculate the redraiment from the No. 0 order to the nth order altogether several walks. Input

Input includes multiple sets of data.
Each set of data includes one row: N (1≤n≤40).
Input ends with 0 Output

The

corresponds to one output for each input. The number of redraiment to which the nth order is reached by the
. Sample Input 1
3
0 Sample Output 1
3

Resolution:
   & nbsp;     if it is not the master to find the law, I am afraid it is difficult to believe that this is the Fibonacci sequence.
         0-----1     1
          0------2     2
          0------3     3
         0------4      5
         0------5     8
The

program is as follows:

#include <cstdio>
int main ()
{
    int a[1000],t,i;
    while ((scanf ("%d", &t) &&t!=0))
    {
        a[0]=1;
        a[1]=2;
        for (i=2;i<t;i++)
        {
           a[i]=a[i-1]+a[i-2];
        }
        if (t<2)
        printf ("1\n");
        else
        printf ("%d\n", A[i-1]);  
    return 0;


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.