【Java】【高精度】【組合數】【遞推】poj1737 Connected Graph

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.