UVa 1646 (递推 JAVA大数) Edge Case

时间:2022-06-28 11:53:37

题意:

有n个点围成一圈,这n个点的匹配就是没有公共点的边集(这些边只能连接一圈中相邻的两点),求所有匹配的个数。

额,我不会分析。。=_=||

算了几个数,找找规律发现它满足斐波那契数列的递推关系,f(n) = f(n-1) + f(n-2)

自从会用了Java的BigInteger,就懒得写C的高精度了。

 import java.io.*;
import java.util.*;
import java.math.*; public class Main
{
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); public static void main(String args[]) throws IOException
{
BigInteger [] a = new BigInteger[10002];
a[3] = new BigInteger("4");
a[4] = new BigInteger("7");
for(int i = 5; i <= 10000; ++i) a[i] = a[i-1].add(a[i-2]);
Scanner cin=new Scanner(System.in);
while(cin.hasNext())
{
int n = cin.nextInt();
System.out.println(a[n]);
}
}
}

代码君