pku 1737 Connected Graph(组合数学,高精度)

  1. package pku1737;
  2. import java.math.BigInteger;
  3. import java.util.*;
  4. public class Main {
  5.     static BigInteger f[];
  6.     public static void main(String[] args) {
  7.         int n;
  8.         Scanner cin = new Scanner(System.in);
  9.          solve();
  10.          while(true){
  11.            n=cin.nextInt();
  12.            if(n==0)break;
  13.            System.out.println(f[n]);
  14.          }
  15.     }
  16.     private static void solve()
  17.     {
  18.         int i,j,n;//System.out.print("ok");
  19.         f=new BigInteger[52];
  20.         BigInteger tmp=new BigInteger("0");
  21.         long c[][]=new long [51][51];
  22.         long two[]=new long [51];
  23.         c[1][0]=c[1][1]=1;
  24.         for(i=2;i<51;i++)//c[i][j]=c[i-1][j-1]+c[i-1][j];
  25.               {      c[i][0]=c[i][i]=1;
  26.                    for(j=1;j<i;j++)
  27.                       c[i][j]=c[i-1][j-1]+c[i-1][j];
  28.               }
  29.         two[0]=1;
  30.         for(i=1;i<=50;i++)two[i]=two[i-1]+two[i-1];
  31.         f[1]=BigInteger.valueOf(1);
  32.         f[2]=BigInteger.valueOf(1);
  33.         f[3]=BigInteger.valueOf(4);
  34.         for(i=4;i<=50;i++)
  35.         {   //f[k]*f[n-k]*c[n-2][k-1]*2^k-1
  36.             f[i]=BigInteger.valueOf(0);
  37.             for(j=1;j<i;j++)
  38.             {
  39.                 tmp=f[j].multiply(f[i-j]);
  40.                 tmp=tmp.multiply(BigInteger.valueOf(c[i-2][j-1]));
  41.                 tmp=tmp.multiply(BigInteger.valueOf(two[j]-1));
  42.                 f[i]=f[i].add(tmp);
  43.             }
  44.         }
  45.     }
  46. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值