标签:
有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行。请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数。
其中,蜂房的结构如下所示:

import java.util.*;
import java.text.*;
public class Main {
public static void main(String[] args){
Scanner cin = new Scanner (System.in);
int t = cin.nextInt();
for(int i=0;i<t;i++)
{
int a,b;
a=cin.nextInt();
b=cin.nextInt();
int n = b - a;
long res =0;
res = test(n) ;
System.out.println(res);
}
}
public static long test(int n)
{
if(n==0||n==1)
return 1;
return test(n-1)+test(n-2);
}
}
标签:
原文地址:http://blog.csdn.net/zhuangjingyang/article/details/43370151