- package pku1737;
- import java.math.BigInteger;
- import java.util.*;
- public class Main {
- static BigInteger f[];
- public static void main(String[] args) {
- int n;
- Scanner cin = new Scanner(System.in);
- solve();
- while(true){
- n=cin.nextInt();
- if(n==0)break;
- System.out.println(f[n]);
- }
- }
- private static void solve()
- {
- int i,j,n;//System.out.print("ok");
- f=new BigInteger[52];
- BigInteger tmp=new BigInteger("0");
- long c[][]=new long [51][51];
- long two[]=new long [51];
- c[1][0]=c[1][1]=1;
- for(i=2;i<51;i++)//c[i][j]=c[i-1][j-1]+c[i-1][j];
- { c[i][0]=c[i][i]=1;
- for(j=1;j<i;j++)
- c[i][j]=c[i-1][j-1]+c[i-1][j];
- }
- two[0]=1;
- for(i=1;i<=50;i++)two[i]=two[i-1]+two[i-1];
- f[1]=BigInteger.valueOf(1);
- f[2]=BigInteger.valueOf(1);
- f[3]=BigInteger.valueOf(4);
- for(i=4;i<=50;i++)
- { //f[k]*f[n-k]*c[n-2][k-1]*2^k-1
- f[i]=BigInteger.valueOf(0);
- for(j=1;j<i;j++)
- {
- tmp=f[j].multiply(f[i-j]);
- tmp=tmp.multiply(BigInteger.valueOf(c[i-2][j-1]));
- tmp=tmp.multiply(BigInteger.valueOf(two[j]-1));
- f[i]=f[i].add(tmp);
- }
- }
- }
- }
pku 1737 Connected Graph(组合数学,高精度)
最新推荐文章于 2013-08-12 14:14:59 发布