hdu2044一只小蜜蜂
有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行。请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数。
其中,蜂房的结构如下所示。
![]()
Input
输入数据的第一行是一个整数N,表示测试实例的个数,然后是N 行数据,每行包含两个整数a和b(0<a<b<50)。 Output对于每个测试实例,请输出蜜蜂从蜂房a爬到蜂房b的可能路线数,每个实例的输出占一行。
Sample Input2 1 2 3 6
Sample Output1 3
斐波拉契![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn=1e6+5; 4 const int INF=1e9+7; 5 long long n,a,b,f[55]; 6 template <class t>void red(t &x) 7 { 8 x=0; 9 int w=1; 10 char ch=getchar(); 11 while(ch<'0'||ch>'9') 12 { 13 if(ch=='-') 14 w=-1; 15 ch=getchar(); 16 } 17 while(ch>='0'&&ch<='9') 18 { 19 x=(x<<3)+(x<<1)+ch-'0'; 20 ch=getchar(); 21 } 22 x*=w; 23 } 24 void input() 25 { 26 freopen("input.txt","r",stdin); 27 } 28 int main() 29 { 30 //input(); 31 red(n); 32 for(int i=1;i<=n;++i) 33 { 34 red(a); 35 red(b); 36 f[a]=1; 37 f[a+1]=1; 38 for(int i=a+2;i<=b;++i) 39 f[i]=f[i-1]+f[i-2]; 40 printf("%lld\n",f[b]); 41 } 42 return 0; 43 }