Hdu 20,441 Little Bees ... (recursive)

Source: Internet
Author: User

A little bee ...

http://acm.hdu.edu.cn/showproblem.php?pid=2044

Time limit:2000/1000 MS (java/others)

Memory limit:65536/32768 K (java/others)

Problem Description

A trained bee can only crawl to the adjacent hive on the right and not crawl in reverse. Please program the number of possible routes by which bees climb from hive A to hive B. The structure of the hive is shown below.

Input

The first line of input data is an integer n that represents the number of test instances, then n rows of data, each containing two integers a and B (0<a<b<50).

This article URL address: http://www.bianceng.cn/Programming/sjjg/201410/45515.htm

Output

For each test instance, export the number of possible routes where the bee crawled from hive A to hive B, and the output of each instance occupies one row.

Sample Input

21 23 6

Sample Output

13

It's clear that lattice n can come from n-1 and n-2, so it's the Fibonacci relationship.

Notice that the a=1,b=49 is a super int, and you want to use long long.

Complete code:

/*0ms,208kb*/
    
#include <cstdio>  
    
long long f[50];  
    
int main ()  
{  
    int T, a, B, I;  
    F[1] = f[2] = 1;  
    for (i = 3; i < ++i) f[i] = F[i-1] + f[i-2];  
    scanf ("%d", &t);  
    while (t--)  
    {  
        scanf ("%d%d", &a, &b);  
        printf ("%i64d\n", F[b-a + 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.