注解
1、递推关系。F(n) = F(n-1) + F(n-2) + F(n-4)
2、大整数。
代码
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
BigInteger[] a = new BigInteger[1001];
a[0] = BigInteger.ONE;
a[1] = BigInteger.ONE;
a[2] = new BigInteger("2");
a[3] = new BigInteger("4");
for(int i=4; i<a.length; i++){
a[i] = a[i-1].add(a[i-2]).add(a[i-4]);
}
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
System.out.println(a[n]);
}
}
}