hdu 2044 a little bee ... simple recursive count (Fibonacci)

Problem Description There is a trained bees can only be climbed right adjacent hive, not the reverse crawl. Calculation program a number of possible routes to climb bee hive from hive b a.
Wherein the honeycomb structure shown below.

Here Insert Picture Description
The first line of input data Input N is an integer, indicates the number of test cases, then the N rows, each row comprising two integers a and b (0 <a <b <50).

Output For each test case, output a number of possible routes to climb the bees from hive hive b a, the output of each row for instance.

Input2 the Sample
. 1 2
. 3. 6
the Sample Output1
. 3
reaches only be reached from the honeycomb b b-1 b-2 or the honeycomb hive, so dis [i] = dis [i -1] + dis [i-2].

#include<bits/stdc++.h>


#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

long long int a[55];

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        a[1] =1;
        a[2] = 2;
        int i;
        for(i=3; i<=50; i++)
        {
            a[i] = a[i-1] + a[i-2];
        }
        cout<<a[m-n]<<endl;
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/weixin_44694282/article/details/89738016