Description
Here is a sample tiling of a 2x17 rectangle.
Input
Output
Sample Input
2 8 12 100 200
Sample Output
3
171
2731
845100400152152934331135470251
1071292029505993517027974728227441735014801995855195223534251
因为写1001时有接触到大数据,所以解这道题就想到了使用JAVA
大数据中JAVA的知识点:http://blog.csdn.net/u010304217/article/details/37728493
思路:公式f[i]=f[i-1]+2*f[i-2]
import java.math.BigInteger;//大整数
import java.util.Scanner;
public class Big {
public static void main(String[] args) {
BigInteger a[]=new BigInteger[400];
Scanner n=new Scanner(System.in);
a[0]=BigInteger.valueOf(1);
a[1]=BigInteger.valueOf(1);
a[2]=BigInteger.valueOf(3);
for(int i=3;i<=250;i++)
{
a[i]=a[i-1].add(a[i-2].multiply(BigInteger.valueOf(2)));
}
while(n.hasNext())
{
System.out.println(a[n.nextInt()]);
}
}
}