### POJ 1737 Connected Graph（JAVA+遞推）

``` 1 import java.io.*;
2 import java.math.*;
3 import java.util.*;
4 import java.text.*;
5 public class Main
6 {
7     public static void main(String[] args)
8     {
9         Scanner cin = new Scanner(System.in);
10         BigInteger[] p;
11         BigInteger sec;
12         p = new BigInteger[101];
13         int i,j;
14         long c[][] = new long [51][51];
15         sec = BigInteger.valueOf(2);
16         for(i = 0;i <= 50;i ++)
17         {
18             c[i][0] = 1;
19         }
20         for(i = 1;i <= 50;i ++)//組合數
21         {
22             for(j = 1;j <= 50;j ++)
23             {
24                 c[i][j] = c[i-1][j-1]+c[i-1][j];
25             }
26         }
27         p[1] = BigInteger.valueOf(1);
28         p[2] = BigInteger.valueOf(1);
29         for(i = 3;i <= 50;i ++)
30         {
31             p[i] = sec.pow((i-1)*i/2);
32             for(j = 1;j <= i-1;j ++)
33             {
34                 p[i] = p[i].subtract(p[j].multiply(BigInteger.valueOf(c[i-1][j-1]).multiply(sec.pow((i-j-1)*(i-j)/2))));
35             }
36         }
37         while(cin.hasNext())
38         {
39             i = cin.nextInt();
40             if(i == 0) break;
41             System.out.println(p[i]);
42         }
43     }
44 }```