標籤:new public details detail math tin break scanner graph
http://blog.csdn.net/sdj222555/article/details/12453629
這個遞推可以說是非常巧妙了。
import java.util.*;import java.io.*;import java.math.*;public class Main{static BigInteger[] g=new BigInteger[60];static BigInteger[] f=new BigInteger[60];static BigInteger[] pow_2=new BigInteger[2510];static long[][] C=new long[60][60];public static void main(String[] argc){C[0][0]=1l; for(int i=1;i<=50;++i){ C[i][0]=C[i][i]=1l; for(int j=1;j<i;++j){ C[i][j]=C[i-1][j]+C[i-1][j-1]; } } pow_2[0]=BigInteger.ONE; for(int i=1;i<=2500;++i){ pow_2[i]=pow_2[i-1].multiply(BigInteger.valueOf(2l)); } g[0]=BigInteger.ONE;for(int i=1;i<=50;++i){g[i]=BigInteger.ZERO;for(int k=1;k<i;++k){g[i]=g[i].add(((BigInteger.valueOf(C[i-1][k-1])).multiply(f[k])).multiply(pow_2[(i-k)*(i-k-1)/2]));}f[i]=pow_2[i*(i-1)/2].subtract(g[i]);}Scanner sc = new Scanner (new BufferedInputStream(System.in));while(true){int n=sc.nextInt();if(n==0){break;}System.out.println(f[n]);}sc.close(); }}
【Java】【高精度】【組合數】【遞推】poj1737 Connected Graph