[Explanations] - hdu super stairs [Fibonacci number distortion]

Super stairs

There are a total of M-class staircase, at the beginning you are in the first stage, if you can only step onto the primary or secondary, to go first M-Class, a total of how many moves?

Input

First, the input data contains an integer N, the number of the test case, then the data of N rows, each row contains an integer M (1 <= M <= 40), indicates the number of stages of the stairs.

Output

For each test case, output a number of different moves

Sample Input

2
2
3

Sample Output

1
2

AC Code

#include <stdio.h>
int main(void)
{
    int n, m, arr[45], i;
    arr[0] = 0;
    arr[1] = 1;
    arr[2] = 2;
    for(i = 3; i <= 40; i ++){
        arr[i] = arr[i - 1] + arr[i - 2];
    }
    scanf("%d",&n);
    while(n --){
        scanf("%d",&m);
        printf("%d\n",arr[m - 1]);
    }
    return 0;
}

Thinking

In fact, the questions that a number of topics listed Feibolaqi thing! We can analyze! Because it can only step onto the primary or secondary, so we reach this level before the walk is 1 order of moves (more step on to our friends) and before the second order of moves (more step on to we have it!) Note Oh! Not selected to go two-by-step! Because we take a step, that is, before the arrival of our first-order, so that the child is in front of us (inside before 1 order of moves included).

This question has two pits, that is our first step in the beginning, in the calculation of the time to pay attention to it.

This question is recursive if there is a time out, so we can play at the table

Published 34 original articles · won praise 2 · Views 905

Guess you like

Origin blog.csdn.net/Kapo1/article/details/103538500