轮状病毒有很多变种,所有轮状病毒的变种都是从一个轮状基产生的。一个N轮状基由圆环上N个不同的基原子
和圆心处一个核原子构成的,2个原子之间的边表示这2个原子之间的信息通道。如下图所示
N轮状病毒的产生规律是在一个N轮状基中删去若干条边,使得各原子之间有唯一的信息通道,例如共有16个不
同的3轮状病毒,如下图所示
现给定n(N<=100),编程计算有多少个不同的n轮状病毒
Input
第一行有1个正整数n
Output
计算出的不同的n轮状病毒数输出
Sample Input
3
Sample Output
16
HINT
Source
基尔霍夫生成树定理 : 用该图度数矩阵 - 领接矩阵生成的矩阵A,A去掉任意一行一列所构成的余子阵A’ ,|detA’| 就是该图生成树的个数 。
import java.util.*;
import java.math.*;
public class Main{
static int maxn = 105;
static BigInteger tot = BigInteger.ONE;
static BigInteger a[][] = new BigInteger[maxn][maxn];
static int n;
static BigInteger lcm(BigInteger x,BigInteger y){
return x.divide(x.gcd(y)).multiply(y);
}
static void debug(){
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++)
System.out.print(a[i][j] + " ");
System.out.println();
}
}
static void Gauss(int equ,int var){
int i,j,k;
int max_r;
int col;
BigInteger ta,tb;
BigInteger LCM;
int temp;
col = 0;
for (k = 0; k < equ && col < var; k++ ,col ++){
max_r = k;
for (i = k + 1; i < equ; i++){
if (a[i][col].abs().compareTo(a[max_r][col].abs()) > 0) max_r = i;
}
if (max_r != k){
for (j = k; j < var + 1; j++)
{
BigInteger t;
t = a[k][j];
a[k][j] = a[max_r][j];
a[max_r][j] = t;
}
}
if (a[k][col].equals(BigInteger.ZERO))
{
k--;
continue;
}
for (i = k + 1; i < equ; i++){
if (!a[i][col].equals(BigInteger.ZERO))
{
LCM = lcm(a[i][col].abs(),a[k][col].abs());
ta = LCM.divide(a[i][col].abs());
tb = LCM.divide(a[k][col].abs());
tot = tot.multiply(ta);
if (a[i][col].multiply(a[k][col]).compareTo(BigInteger.ZERO) < 0) tb = tb.multiply(BigInteger.valueOf(-1));
for (j = col; j < var + 1; j++){
a[i][j] = a[i][j].multiply(ta).subtract(a[k][j].multiply(tb));
}
}
}
}
}
public static void main(String agrs[]){
Scanner cin = new Scanner(System.in);
n = cin.nextInt();
for (int i = 0; i < n + 1; i++){
for (int j = 0; j < n + 1; j++)
a[i][j] = BigInteger.ZERO;
}
for (int i = 0; i < n; i++){
a[i][i + 1] = BigInteger.valueOf(-1);
a[i + 1][i] = BigInteger.valueOf(-1);
a[i][i] = BigInteger.valueOf(3);
}
a[n - 1][0] = BigInteger.valueOf(-1);
a[0][n - 1] = BigInteger.valueOf(-1);
Gauss(n,n);
BigInteger ans = BigInteger.ONE;
for (int i = 0; i < n; i++) ans = ans.multiply(a[i][i]);
if (n == 2) System.out.println("5");
else System.out.println(ans.divide(tot).abs());
}
}