A small bee ...
Subject description:
There are 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
The 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 6Sample Output
1 3
By the answer:
#include<stdio.h> //递推:斐波那契数列
int main(){
int n,i,a,b;
long long str[100]; //注意:数组为long long型:是64位的整型
while(scanf("%d",&n)!=EOF){
while(n--){
scanf("%d %d",&a,&b);
str[a]=1; //第n格里蜜蜂可以爬到第n+1, n+2格子里。这又是一个斐波那契数列。
str[a+1]=1;
str[a+2]=2;
for(i=a+3;i<=50;i++){ // 0<a<b<50
str[i]=str[i-1]+str[i-2];
}
printf("%lld\n",str[b]);
}
}
return 0;
}