[poj1737]Connected Graph(连通图计数)
题意:输出题中带有$n$个标号的图中连通图的个数。
解题关键:
令$f(n)$为连通图的个数,$g(n)$为非联通图的个数,$h(n)$为总的个数。
则$f(n) + g(n) = h(n)$
考虑标号1所在的联通分量中连通图的个数。
转移方程:$g(n) = \sum\limits_{k = 1}^{n - 1} {C_{n - 1}^{k - 1}f(k)h(n - k)} $
$h(n) = \frac{{n(n - 1)}}{2}$
import java.math.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
BigInteger h[]=new BigInteger [55],C[][]=new BigInteger[55][55];
C[0][0]=BigInteger.ONE;
for(int i=0;i<=50;i++){//预处理组合数
C[i][0]=C[i][i]=BigInteger.ONE;
for(int j=1;j<i;j++){
C[i][j]=C[i-1][j].add(C[i-1][j-1]);
}
}
for(int i=1;i<=50;i++) h[i]=BigInteger.valueOf(2).pow(i*(i-1)/2);
BigInteger f[]=new BigInteger[55],g[]=new BigInteger[55];
f[1]=BigInteger.ONE;
for(int i=1;i<=50;i++) {
g[i]=BigInteger.ZERO;
for(int j=1;j<i;j++) {
g[i]=g[i].add(C[i-1][j-1].multiply(f[j]).multiply(h[i-j]));
}
f[i]=h[i].subtract(g[i]);
}
Scanner in=new Scanner(System.in);
while(in.hasNext()){
int n=in.nextInt();
if(n==0) break;
System.out.println(f[n]);
}
} }
[poj1737]Connected Graph(连通图计数)的更多相关文章
- POJ1737 Connected Graph
Connected Graph Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3156 Accepted: 1533 D ...
- $Poj1737\ Connected\ Graph$ 计数类$DP$
AcWing Description 求$N$个节点的无向连通图有多少个,节点有标号,编号为$1~N$. $1<=N<=50$ Sol 在计数类$DP$中,通常要把一个问题划分成若干个子问 ...
- 【Java】【高精度】【组合数】【递推】poj1737 Connected Graph
http://blog.csdn.net/sdj222555/article/details/12453629 这个递推可以说是非常巧妙了. import java.util.*; import ja ...
- poj 1737 Connected Graph
// poj 1737 Connected Graph // // 题目大意: // // 带标号的连通分量计数 // // 解题思路: // // 设f(n)为连通图的数量,g(n)为非连通图的数量 ...
- POJ 1737 Connected Graph 题解(未完成)
Connected Graph Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3156 Accepted: 1533 D ...
- Connected Graph
Connected Graph 求n个点的无向联通图数量,\(n\leq 50\). 解 直接无向联通图做状态等于是以边点做考虑,难以去重,考虑联通对立面即不联通. 不难求出n个点的总方案数为\(2^ ...
- 【poj1737】 Connected Graph
http://poj.org/problem?id=1737 (题目链接) 题意 求n个节点的无向连通图的方案数,不取模w(゚Д゚)w Solution 刚开始想了个第二类斯特林数,然而并不知道怎么求 ...
- 【XSY1295】calc n个点n条边无向连通图计数 prufer序列
题目大意 求\(n\)个点\(n\)条边的无向连通图的个数 \(n\leq 5000\) 题解 显然是一个环上有很多外向树. 首先有一个东西:\(n\)个点选\(k\)个点作为树的根的生成森林个数为: ...
- 【BZOJ3456】轩辕朗的城市规划 无向连通图计数 CDQ分治 FFT 多项式求逆 多项式ln
题解 分治FFT 设\(f_i\)为\(i\)个点组成的无向图个数,\(g_i\)为\(i\)个点组成的无向连通图个数 经过简单的推导(枚举\(1\)所在的连通块大小),有: \[ f_i=2^{\f ...
随机推荐
- jquery 如何获取单选框的值
jquery 如何获取单选框的值 获取单选框的值有三种方式: 1.$('input:radio:checked').val():2.$("input[type='radio']:chec ...
- linux FAQ(zz)
1.Which is the command used to find the available shells in your Operating System Linux ? Ans : $ech ...
- tornado源码分析
初识tornado 首先从经典的helloword案例入手 import tornado.ioloop import tornado.web class MainHandler(tornado.web ...
- 高通8X16电池BMS算法(一)【转】
本文转载自:http://www.voidcn.com/blog/yanleizhouqing/article/p-6037399.html 最近一直在搞电源管理相关内容,之前是8610的bms,现在 ...
- GetTickCount的几个案例
一,获得运行时间: var T1,T2 : double; begin T1 := GetTickCount; //需要做的事情 T2 := GetTickCount; ShowMessage( fl ...
- js里对php存贮的cookie进行读取和删除
/* 读取cookie */ function getCookie(name){ var arr,reg=new RegExp("(^| )"+name+"=([^;]* ...
- Oracle结构控制语句
--if语句 if [判断条件] then --条件满足执行的语句 end if; -- if ...else... if [判断条件] then ----条件满足执行的语句 else --不满足条件 ...
- 2015年SCI收录遥感期刊28种目录
链接地址:http://blog.sciencenet.cn/blog-57081-928025.html
- java:Map借口及其子类HashMap二
java:Map借口及其子类HashMap二 重点:所有的集合必须依赖Iterator输出 Map<String, Integer> map = new HashMap<String ...
- 分享知识-快乐自己:mybatis 主键回调
以下两种方式实现 主键回掉方式. <!--添加用户信息:主键回调--> <insert id="insertUser" useGeneratedKeys=&quo ...