Problem Description
有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行。请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数。
其中,蜂房的结构如下所示。
Input
输入数据的第一行是一个整数N,表示测试实例的个数,然后是N 行数据,每行包含两个整数a和b(0
Output
对于每个测试实例,请输出蜜蜂从蜂房a爬到蜂房b的可能路线数,每个实例的输出占一行。
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
public static void main(String []args){
Scanner cin = new Scanner(System.in);
Integer N = 50,i,n,a,b;
BigInteger[] fm = new BigInteger[N];
fm[1] = fm[2] = BigInteger.valueOf(1);
for(i = 3; i < N; ++i)
fm[i] = fm[i-1].add(fm[i-2]);
n = cin.nextInt();
for(i = 0; i < n; ++i){
a = cin.nextInt();
b = cin.nextInt();
b = b - a + 1;
System.out.println(fm[b]);
}
}
}
Problem Description
有一个大小是 2 x n 的网格,现在需要用2种规格的骨牌铺满,骨牌规格分别是 2 x 1 和 2 x 2,请计算一共有多少种铺设的方法。
Input
输入的第一行包含一个正整数T(T<=20),表示一共有 T组数据,接着是T行数据,每行包含一个正整数N(N<=30),表示网格的大小是2行N列。
Output
输出一共有多少种铺设的方法,每组数据的输出占一行。
Sample Input
3
2
8
12
Sample Output
3
171
2731
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
public static void main(String []args){
Scanner cin = new Scanner(System.in);
Integer N = 50,i,n,a,b;
BigInteger[] fm = new BigInteger[N];
fm[0] = BigInteger.valueOf(2);
fm[1] = BigInteger.valueOf(1);
fm[2] = BigInteger.valueOf(3);
for(i = 3; i < N; ++i)
fm[i] = fm[i-1].add(fm[i-2].multiply(fm[0]));
n = cin.nextInt();
for(i = 0; i < n; ++i){
b = cin.nextInt();
System.out.println(fm[b]);
}
}
}