UVA - 1646 - Edge Case(找規律)

題意:n(3 <= n <= 10000)個結點組成一個圈,求匹配(即沒有公共點的邊集)的個數。java

找規律爲斐波那契的性質,由於數太大因此用的java大數。spa

import java.math.BigInteger;
import java.util.Scanner;
public class Main{
    public static int MAXN = 10000 + 10;
    public static BigInteger []c = new BigInteger[MAXN];
    public static void init(){
        c[3] = new BigInteger("4");
        c[4] = new BigInteger("7");
        for(int i = 5; i < MAXN; ++i)
            c[i] = c[i - 1].add(c[i - 2]);
    }
    public static void main(String []args){
        init();
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextInt()){
            int n = sc.nextInt();
            System.out.println(c[n]);
        }
    }
}
相關文章
相關標籤/搜索