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 |
#include<iostream>
#include<string.h>
using namespace std;
long long a[50]={1,1,2,3}; // 菲波那切数列 数据太大 不好计算 可以先放在数组里 累加 更容易
int main (){
int n,i,j;
cin>>n;
while (n--){
for(int m=2;m<50;m++)
a[m]= a[m-1]+a[m-2]; // 计算 菲波那切数列
scanf("%d%d",&i,&j);
printf("%d\n",a[j-i]);
}return 0;
}