"Java" "High precision" "combination number" "recursion" poj1737 Connected Graph

Source: Internet
Author: User

http://blog.csdn.net/sdj222555/article/details/12453629

This recursion can be said to be very ingenious.

import java.util.*;import java.io.*;import java.math.*;p ublic 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];p ublic 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, high precision, combined number "recursion" poj1737 Connected Graph

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.