POJ 1737 Connected Graph
来源:互联网 发布:centos搭建mc服务器 编辑:程序博客网 时间:2024/05/21 18:33
题意:求 n 个点的无向简单带标号联通图个数。
记 f[n] 是所求答案,g[n] 是 n 个点的不联通图个数,f[n] + g[n] = h[n] = 2 ^ ((n*(n-1)/2)
设 1 所在联通块有 k 个点, 1<=k<n
Connected Graph
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 2945 Accepted: 1445
Description
An undirected graph is a set V of vertices and a set of E∈{V*V} edges.An undirected graph is connected if and only if for every pair (u,v) of vertices,u is reachable from v.
You are to write a program that tries to calculate the number of different connected undirected graph with n vertices.
For example,there are 4 different connected undirected graphs with 3 vertices.
You are to write a program that tries to calculate the number of different connected undirected graph with n vertices.
For example,there are 4 different connected undirected graphs with 3 vertices.
Input
The input contains several test cases. Each test case contains an integer n, denoting the number of vertices. You may assume that 1<=n<=50. The last test case is followed by one zero.
Output
For each test case output the answer on a single line.
Sample Input
12340
Sample Output
11438
Source
LouTiancheng@POJ
/** * Created by OI_lover on 2015/4/9. */import java.io.*;import java.util.*;import java.math.BigInteger;import static java.math.BigInteger.*;public class Main { public static final int N = 55; public static void main(String[] args) throws Exception { BigInteger []h = new BigInteger[N]; BigInteger []f = new BigInteger[N]; BigInteger []g = new BigInteger[N]; BigInteger p2[] = new BigInteger[N*N]; BigInteger [][]C = new BigInteger[N][N]; for (int i=0;i<N;i++) { for (int j=0;j<=i;j++) { if (i==j || j==0) C[i][j] = valueOf(1); else C[i][j] = C[i-1][j-1].add(C[i-1][j]); } } p2[0] = ONE; for (int i=1;i<N*N;i++) p2[i] = p2[i-1].multiply(valueOf(2)); for (int i=0;i<N;i++) h[i] = p2[i*(i-1)/2]; f[1] = BigInteger.valueOf(1); g[1] = BigInteger.valueOf(0); for (int n=2;n<N;n++) { g[n] = BigInteger.ZERO; for (int k = 1;k < n; k++) { BigInteger t = C[n-1][k-1].multiply(f[k]); t = t.multiply(h[n-k]); g[n] = g[n].add(t); f[n] = h[n].subtract(g[n]); } } Scanner in = new Scanner(System.in); while (in.hasNext()) { int n = in.nextInt(); if (n == 0) break; System.out.println(f[n]); } }}
0 0
- poj 1737 Connected Graph
- poj 1737 Connected Graph
- POJ 1737 Connected Graph
- POJ 1737 Connected Graph
- POJ 1737 Connected Graph 递推
- POJ 1737 Connected Graph 题解(未完成)
- POJ 1737 Connected Graph 高进度+递推
- poj 1737 Connected Graph 组合递推计数+高精度
- Connected Graph
- Nodally 3-connected graph
- poj1737 Connected Graph
- POJ1737 Connected Graph【数学】
- Connected Graph POJ1737 高精度
- poj1737 Connected Graph(组合数学)
- Connected Component in Undirected Graph
- sicily connected components in undiected graph
- Sicily 1002. connected components in undirected graph
- LintCode 431 Connected Component in Undirected Graph
- 黑马程序员 ------Static关键字的学习
- 第一章 HBase简介
- python 学习笔记之字典
- C 语言:指针、free()与 NULL
- PHP.INI配置:文件上传功能配置教程
- POJ 1737 Connected Graph
- 程序员的编程心法--序章
- 读《程序员编程艺术》之自造Java版本-----字符串左移
- 搭建web服务器
- Qt单元测试浅析
- ubuntu-git远程仓库管理
- 黑马程序员
- FKJAVA读书笔记--第十五章--输入/输出(修改)
- 基础练习 数列排序