一隻小蜜蜂

有一隻通過訓練的蜜蜂只能爬向右側相鄰的蜂房,不能反向爬行。請編程計算蜜蜂從蜂房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>
using namespace std;
int main()
{
long long a[55];
int j,x,y,n;
cin>>n;
while(n--)
{
cin>>x>>y;
a[0]=1;
a[1]=1;
for(j=2;j<=y-x;j++)
{
a[j]=a[j-1]+a[j-2];
}
cout<<a[y-x]<<endl;
if(n==0) break;
}
return 0;
}ios

相關文章
相關標籤/搜索