[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…
Connected Graph Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3156   Accepted: 1533 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)…
AcWing Description 求$N$个节点的无向连通图有多少个,节点有标号,编号为$1~N$. $1<=N<=50$ Sol 在计数类$DP$中,通常要把一个问题划分成若干个子问题,以便于执行递推. 一个连通图不容易划分,而一个不连通的无向图则很容易划分成结点更少的两部分.所以我们把问题转化成用$N$个点的无向图总个数减去$N$个点的不连通无向图的个数. $N$个点的无向图总个数显然是$2^{N*(N-1)/2}$,还是简单说下叭,就是$N$个点连成完全图的边数显然是$N*(N-1)…
http://blog.csdn.net/sdj222555/article/details/12453629 这个递推可以说是非常巧妙了. import java.util.*; import java.io.*; import java.math.*; public class Main{ static BigInteger[] g=new BigInteger[60]; static BigInteger[] f=new BigInteger[60]; static BigInteger[…
// poj 1737 Connected Graph // // 题目大意: // // 带标号的连通分量计数 // // 解题思路: // // 设f(n)为连通图的数量,g(n)为非连通图的数量,h(n)为所有的 // 图的数量,h(n) = 2 ^(n * (n - 1) / 2); // f(n) + g[n] = h(n). // // 考虑标号为1在哪个连通分量内,设连通分量内有k个点,则问题为 // 在n-1个点中选择k-1个点的方法数 C(n-1,k-1),此时1所在的连通图数…
Connected Graph Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3156   Accepted: 1533 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)…
Connected Graph 求n个点的无向联通图数量,\(n\leq 50\). 解 直接无向联通图做状态等于是以边点做考虑,难以去重,考虑联通对立面即不联通. 不难求出n个点的总方案数为\(2^{\frac{n\times (n-1)}{2}}\),所以设\(f_i\)表示n个点的无向联通图个数,因此我们有 \[f_i=2^{\frac{n(n-1)}{2}}-\sum_{j=1}^{i-1}f_jC_i^j2^{\frac{(i-j)(i-j-1)}{2}}\] 但是这样的转移存在重复,…
http://poj.org/problem?id=1737 (题目链接) 题意 求n个节点的无向连通图的方案数,不取模w(゚Д゚)w Solution 刚开始想了个第二类斯特林数,然而并不知道怎么求具体方案,于是翻了题解.. 设${f_n}$表示n个节点的方案数. 那么n个节点所能够构成的无向图,无论连不连通,一共有${\frac{n*(n+1)}{2}}$条边,于是就有${2^{\frac{n*(n+1)}{2}}}$种图.考虑如何减去不连通的图的方案数. 我们选择枚举1号节点与i个节点连通…
题目大意 求\(n\)个点\(n\)条边的无向连通图的个数 \(n\leq 5000\) 题解 显然是一个环上有很多外向树. 首先有一个东西:\(n\)个点选\(k\)个点作为树的根的生成森林个数为: \[ \binom{n}{k}\times n^{n-k-1}\times k \] 前面\(\binom{n}{k}\)是这些根的选编号的方案数,后面是prufer序列得到的:前面\(n-k-1\)个数可以是\(1\)~\(n\),第\(n-k\)个数是\(1\)~\(k\). 我的理解是:每个…
题解 分治FFT 设\(f_i\)为\(i\)个点组成的无向图个数,\(g_i\)为\(i\)个点组成的无向连通图个数 经过简单的推导(枚举\(1\)所在的连通块大小),有: \[ f_i=2^{\frac{i(i-1)}{2}} \] \[ \begin{align} g_i&=f_i-\sum_{j=1}^{i-1}\binom{n-1}{j-1}g_jf_{i-j}\\ &=f_i-(i-1)!\sum_{j=1}^{i-1}\frac{g_j}{(j-1)!}\frac{f_{i-…
题目大意 ​ 给你\(n,p\),求\(n\)个点组成的所有无向连通图的边数的平方和模\(p\) ​ \(n\leq 2000,p\leq {10}^9\) 题解 ​ 设\(m=\frac{n(n-1)}{2},h0_n=n\)个点无向图的个数,\(h1_n=n\)个点组成的所有无向图的边数之和,\(h2_n=n\)个点组成的所有无向图的边数的平方和,\(f0_n=n\)个点无向连通图的个数,\(f1_n=n\)个点组成的所有无向连通图的边数之和,\(f2_n=n\)个点组成的所有无向连通图的边…
题面 \(solution:\) 首先做个推销:带负数的压位高精度(加减乘+读写) 然后:由 \(N\) 个节点组成的无向图的总数为: \(2^{N*(N-1)/2}\) (也就是说这个图总共有 \(N*(N-1)/2\) 条边,每一条边选或不选就可以得出来) 然后我们直接开始分析题目,因为这道题需要求无向连通图的方案数,这道题似乎也不是一个结论题, \(wch\) 决定去找找规律,是不是 \(n\) 和 \(n-1\) 有什么关系,但是 $wch $ 发现他打不出表. 然后 $wch $ 想到…
题目链接: http://poj.org/problem?id=1737 题意: 求 \(n\) 个点的无向简单(无重边无自环)连通图的个数.\((n<=50)\) 题解: 这题你甚至能OEIS. http://oeis.org/A001187 但不支持这样做.TAT 间接做. 总方案数减去不合法方案. 因为\(n\)个点的完全图有 \(C(n,2)={n(n-1) \over 2}\) 条边,显然就有 \(2^{C(n,2)}\) 种子图,即枚举每条边是否选择. 设$ f[i]$ 表示每个点都…
\(\mathcal{Description}\)   link.   求包含 \(n\) 个点的边双连通图的个数.   \(n\le10^5\). \(\mathcal{Solution}\)   类似于这道题,仍令 \(D(x)\) 为有根无向连通图的 \(\text{EGF}\),\(B(x)\) 为边双连通图的 \(\text{EGF}\),考虑用 \(B\) 表示 \(D\).显然,根仅存在于一个边双连通分量中.我们可以在这个连通分量的任意一个点上挂一个有根连通图,这显然不会影响当前的…
\(\mathcal{Description}\)   link.   求有 \(n\) 个结点的点双连通图的个数,对 \(998244353\) 取模.   \(n\le10^5\). \(\mathcal{Solution}\)   奇怪的 GF 增加了 w!   对于带标号简单无向图,其 \(\text{EGF}\) 为 \(F(x)=\displaystyle\sum_{i=0}^{+\infty}\frac{2^{i\choose2}x^i}{i!}\)(任意两点间有连与不连两种情况.…
记$G[S]$表示图$G$在点集$S$上的导出子图,即$G[S]=(S,{(x,y)|x,y\in S且(x,y)\in E})$ 定义$g(S)$为所有$E'$(满足$E'\subseteq G[S].E$)的图$G'=(S,E')$的染色方式之和,考虑枚举其中一种颜色的点集,则有$g(S)=\sum_{T\subseteq S}2^{|\{(x,y)|(x,y)\in E且x\in T且y\in C_{S}T\}|}$(这些边可以选或不选) 考虑计算$|\{(x,y)|(x,y)\in G[…
一.数据结构 data 数据data element 数据元素data item 数据项data object 数据对象data structure 数据结构ADT (Abstruct Date Type) 抽象数据类型alogrithm 算法correctness 正确性readability 可读性robustness 健壮性frequency count 频度asymptotic time complexity 渐进时间复杂度space complexity 空间复杂度storage de…
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree. For example: Given n = 5 and edges = [[0, 1], [0, 2], [0, 3], [1, 4]], return tru…
Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th…
背景 不同的数据结构有不同的用途,像:数组.链表.队列.栈多数是用来做为基本的工具使用,二叉树多用来作为已排序元素列表的存储,B 树用在存储中,本文介绍的 Graph 多数是为了解决现实问题(说到底,所有的数据结构都是这个目的),如:网络布局.任务安排等. 图的基本概念 示例 顶点(Vertex) 上图的 1.2.3.4.5.6 就是顶点. 邻接(Adjoin) 如果 A 和 B 通过定向边相连,且方向为 A -> B,则 B 为 A 的邻接,如果相连的边是没有方向的,则 A 和 B 互为邻接.…
[抄题]: Given an undirected graph, return true if and only if it is bipartite. Recall that a graph is bipartite if we can split it's set of nodes into two independent subsets A and B such that every edge in the graph has one node in A and another node…
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree. For example: Given n = 5 and edges = [[0, 1], [0, 2], [0, 3], [1, 4]], return tru…
论文信息 论文标题:Towards Deeper Graph Neural Networks论文作者:Meng Liu, Hongyang Gao, Shuiwang Ji论文来源:2020, KDD论文地址:download 论文代码:download 1 Introduction 问题引入: 图卷积是领域聚合的代表,这些邻域聚合方法中的一层只考虑近邻,当进一步深入以实现更大的接受域时,性能会下降,这种性能恶化归因于过平滑问题( over-smoothing),即当感受域增大时,在传播和更新过…
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree. For example: Given n = 5 and edges = [[0, 1], [0, 2], [0, 3], [1, 4]], return tru…
Strongly Connected Components A directed graph is strongly connected if there is a path between all pairs of vertices. A strongly connected component (SCC) of a directed graph is a maximal strongly connected subgraph. For example, there are 3 SCCs in…
题面 Time limit : 2sec / Memory limit : 1024MB Score : 600 points Problem Statement-题目描述 Kenkoooo found a simple connected graph. The vertices are numbered 1" role="presentation">11 through n" role="presentation">nn. The…
题目分析 n个点的二分染色图计数 很显然的一个式子 \[ \sum_{i=0}^n\binom{n}{i}2^{i(n-i)} \] 很容易把\(2^{i(n-i)}\)拆成卷积形式,前面讲过,不再赘述. n个点的二分图计数 设\(f_n\)表示n个点的二分染色图个数. 设\(g_n\)表示n个点的二分连通图个数. 设\(h_n\)表示n个点的二分图个数. 分别构造f,g,h的EGF\(F,G,H\). 显然有 \[ \begin{aligned} F&=\sum_i(2*G)^i=e^{2G}…
地址:http://codeforces.com/problemset/problem/165/D 题目: D. Beard Graph time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Let's define a non-oriented connected graph of n vertices and n - 1 edg…
D. Valid Sets time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree…
Question: Detect cycle in a directed graph Answer: Depth First Traversal can be used to detect cycle in a Graph. DFS for a connected graph produces a tree. There is a cycle in a graph only if there is a back edge present in the graph. A back edge is…