HDU2044 a small bee ... (simple recursive)

A small bee ...

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 112363    Accepted Submission(s): 39714

Problem Description

There are 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.

Input

The first line of input data 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.

Sample Input

2 1 2 3 6

Sample Output

1 3

This question is like a very long time, in fact, quite simple, my idea is to use an array of data storage, and then hit the table.

Note there are two points:

①a[i]=a[i-1]+a[1-2]

② the beginning of the definition of a [50] is always an int WA, later changed to a double on the AC.

code show as below:

#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    int n;
    int first,last;
    double a[50];
    a[1]=1;
    a[2]=1;
    a[3]=2;
    for(int i=4;i<=50;i++){
        a[i]=a[i-1]+a[i-2];
    }
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d %d",&first,&last);
        printf("%.0f",a[last-first+1]);
        printf("\n");
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/jianqiao123/p/11223545.html