【大数问题】 HDOJ 1250 Hat's Fibonacci

又一道大数。。。

import java.util.Scanner;
import java.math.BigInteger;
import java.math.BigDecimal;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		BigInteger f[] = new BigInteger[10005];
		f[1] = BigInteger.valueOf(1);
		f[2] = f[3] = f[4] = f[1];
		for(int i = 5; i <= 10000; i++) {
			f[i] = BigInteger.ZERO;
			f[i] = f[i].add(f[i-1]);
			f[i] = f[i].add(f[i-2]);
			f[i] = f[i].add(f[i-3]);
			f[i] = f[i].add(f[i-4]);
		}
		while(scanner.hasNext()) {
			int n = scanner.nextInt();
			System.out.println(f[n]);
		}
	}
}


你可能感兴趣的:(HDU)