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.
 

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

Sample Output

Source

必须膜icefox巨佬 真的太强啦qwq 这题很神 leoly:常说:输入一个数 输出一个数 是不是很妙啊 题意:求给N个节点 问n个节点全连通的个数有多少种 设f[n]表示n个节点我的连通图个数 怎么做 首先假设我需要将图分成两个只通过一条边连接的图那么两边我都可以用f[k],f[n-k]来表示状态 此时我两边各选一个代表将其固定下来 假设左边是k个右边是n-k个 那么左边满足连通 至少是我选定的那个点和其他k-1个点都有边这k-1个点怎么选 $ C_{n-2}^{k-1}$好了这样我强行钦定左边连通了 那么k个点连通的方案数我有了就是f[k]这是选出哪k个点 同时我还需要满足我这两个连通块是连通的那么我需要通过另外一个连通块内钦定的点相连 那么一共是$2^{k}-1$种方案 因为不能不连通 最后总的递推式子写出 $f[n]=\sum_{k=1}^{n-1}f[k]*f[n-k]*C_{n-2}^{k-1}*(2^{k}-1)$ 得写高精orz

 


elijahqi

辣鸡蒟蒻一枚qwq 欢迎加qq qwq 2922945330

发表评论