航电 Problem 2044一直小蜜蜂

                                                          一只小蜜蜂...

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


Problem Description
有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行。请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数。
其中,蜂房的结构如下所示。

 

Input
输入数据的第一行是一个整数N,表示测试实例的个数,然后是N 行数据,每行包含两个整数a和b(0<a<b<50)。
 

Output
对于每个测试实例,请输出蜜蜂从蜂房a爬到蜂房b的可能路线数,每个实例的输出占一行。
 

Sample Input
2 1 2 3 6
 

Sample Output
1 3
 

Author
lcy
 这道题考察Fibonacci数列的递推,要想知道到达b的线路,知道到达b-1和b-2的线路有多少,相加就是到达b的线路总数。
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAX_N 205
using namespace std;

__int64 ar[MAX_N];
int main() {
    __int64 t, a, b;
    scanf("%I64d", &t);
    while (t--) {
		scanf("%I64d%I64d", &a, &b);
		ar[a + 1] = 1;
		ar[a + 2] = 2;
		for (int i = a + 3; i <= b; i++) {
			ar[i] = ar[i - 1] + ar[i - 2];
		}
		printf("%I64d
", ar[b]);
    }
    return 0;
}


 

Recommend
原文地址:https://www.cnblogs.com/cniwoq/p/6770947.html