Problem Description
There is 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
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
1-> Article 11
1-> 21 Article
1-> Article 321-> 2-> 31->. 3
1-> 43 Article 1-> 2-> 41-> 3-> 4 1 -> 2-> 3-> 4
we find a [i] = a [i -1] + a [i-2]
1-> 4 must be equal to the number of strings 1-> Route 3 Route count + 1-> 2, as 1-> 4 must pass on the way 2 and 3
Similarly, the number of routes 1-> 5 must be equal to the number of strings 1-> 3 + 1-> 4, since the road 5 1-> 3 and 4 must pass
Number Route 3-> 6 may be converted to a number of our scheme 1 -> 4 (Figure know), so we x-> y are converted into 1-> y-x + 1 can
#include<bits/stdc++.h>
using namespace std;
long long a[55];
int main()
{
a[1]=1;
a[2]=1;
for(int i=3;i<=50;i++)
a[i]=a[i-1]+a[i-2];
int N;
cin>>N;
while(N--)
{
int x,y;
cin>>x>>y;
cout<<a[y-x+1]<<endl;
}
return 0;
}
Recursive algorithms Summary:
recursive algorithm