POJ1737 Connected Graph
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 3156 | Accepted: 1533 |
Description
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
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
Sample Input
1
2
3
4
0
Sample Output
1
1
4
38
Source
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
打表
然后是我一直改不对的代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
struct bgnum{
int l;
int a[];
bgnum operator + (const bgnum &x) const{
bgnum ans;
memset(ans.a,,sizeof(ans.a));
int len=max(l,x.l);
ans.l=;
for(int i=;i<=len;i++){
ans.a[i]+=a[i]+x.a[i];
ans.a[i+]+=ans.a[i]/;
ans.a[i]%=; }
len++;
while(!ans.a[len]&&len)len--;
ans.l=len;
return ans;
}
bgnum operator - (const bgnum &x) const{
bgnum ans;
memset(ans.a,,sizeof(ans.a));
for(int i=;i<=l;i++){
ans.a[i]+=a[i]-x.a[i];
if(ans.a[i]<){
ans.a[i]+=;
ans.a[i-]--;
}
}
ans.l=l;
while(!ans.a[ans.l] && ans.l) ans.l--;
return ans;
}
bgnum operator * (const bgnum &x) const{
bgnum ans;
memset(ans.a,,sizeof(ans.a));
for(int i=;i<=l;i++)
for(int j=;j<=x.l;j++){
ans.a[i+j-]+=a[i]*x.a[j];
ans.a[i+j]+=ans.a[i+j-]/;
ans.a[i+j-]%=;
}
int len=l+x.l;
while(!ans.a[len] && len)len--;
ans.l=len;
return ans;
}
}f[],//[i]个点构不同图的方案数
c[][],//[i]个点中选[j]个任意连边的方案数
mi[],//2的[i]次方
sum; void Print(bgnum p){
for(int i=p.l;i>=;i--){
printf("%d",p.a[i]);
}
printf("\n");
return;
}
bgnum p1,p2;
int main(){
p1.l=;p1.a[]=;//高精度数1
p2.l=;p2.a[]=;//高精度数2
int i,j;
mi[]=p1;
for(i=;i<=;i++)
mi[i]=mi[i-]*p2;
for(i=;i<=;i++)
c[i][]=p1;
for(i=;i<=;i++)
for(j=;j<=i;j++){
c[i][j]=c[i-][j]+c[i-][j-];//组合数递推公式
}
for(i=;i<=;i++){
sum.l=;
memset(sum.a,,sizeof(sum.a));
for(j=;j<i;j++){
sum=sum+(c[i-][j-]*f[j]*mi[(i-j)*(i-j-)/]);
}
// Print(sum);
f[i]=mi[i*(i-)/]-sum;
}
int n;
scanf("%d",&n);
Print(f[n]);
return ;
}
再放隔壁某dalao的AC题解
http://blog.csdn.net/orion_rigel/article/details/51812864
POJ1737 Connected Graph的更多相关文章
- 【Java】【高精度】【组合数】【递推】poj1737 Connected Graph
http://blog.csdn.net/sdj222555/article/details/12453629 这个递推可以说是非常巧妙了. import java.util.*; import ja ...
- [poj1737]Connected Graph(连通图计数)
题意:输出题中带有$n$个标号的图中连通图的个数. 解题关键: 令$f(n)$为连通图的个数,$g(n)$为非联通图的个数,$h(n)$为总的个数. 则$f(n) + g(n) = h(n)$ 考虑标 ...
- $Poj1737\ Connected\ Graph$ 计数类$DP$
AcWing Description 求$N$个节点的无向连通图有多少个,节点有标号,编号为$1~N$. $1<=N<=50$ Sol 在计数类$DP$中,通常要把一个问题划分成若干个子问 ...
- 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 刚开始想了个第二类斯特林数,然而并不知道怎么求 ...
- POJ 1737 Connected Graph(高精度+DP递推)
题面 \(solution:\) 首先做个推销:带负数的压位高精度(加减乘+读写) 然后:由 \(N\) 个节点组成的无向图的总数为: \(2^{N*(N-1)/2}\) (也就是说这个图总共有 \( ...
- POJ 1737 Connected Graph (大数+递推)
题目链接: http://poj.org/problem?id=1737 题意: 求 \(n\) 个点的无向简单(无重边无自环)连通图的个数.\((n<=50)\) 题解: 这题你甚至能OEIS ...
随机推荐
- java 21 - 2 字符输出流
字符输出流:OutputStreamWriter 构造方法:一共4个,说2个常用的 A:OutputStreamWriter(OutputStream out):根据默认编码把字节流的数据转换为字符流 ...
- css3实现立方体的旋转功能
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 5050 [JL] 他爱上了鸭蛋
5050 [JL] 他爱上了鸭蛋 时间限制: 1 s 空间限制: 1000 KB 题目等级 : 白银 Silver 题解 题目描述 Description 小明爱上了零鸭蛋.他喜欢输 ...
- 007医疗项目-模块一:用户的查找:3.用户表查询的Action和Service
这里主要写Action和Service. 先写Service层: 架构如下:
- Ubuntu优化-py用机器
关闭防火墙 ufw disable pip换源 yum install python-pip -y mkdir ~/.pip cat > pip.conf<<a [global] i ...
- 【.NET】传智播客第【19】期就业班视频(高清无加密)
[.NET]传智播客第[19]期就业班视频(高清无加密) 下载地址:http://fu83.cn/thread-85-1-1.html
- 获取元素的xpath, 转换xpath为csspath进行jQuery元素获取
获取元素的xpath, 转换xpath为csspath进行jQuery元素获取 博客分类: 编程心得 jQueryCSSHTML var $shadow = new Object(); /** 获取 ...
- [matlab]改变矩阵的大小并保存到txt文件
要完成的任务是,加载一个保存在txt文件中的矩阵, 并把它扩大10倍,并且要再次保存回去 %加载txt文件 >load('Matrix.txt'); %扩大10倍 repmat(Matrix,r ...
- [CareerCup] 6.1 Find Heavy Bottle 寻找重瓶子
6.1 You have 20 bottles of pills. 19 bottles have 1.0 gram pills, but one has pills of weight 1.1 gr ...
- 第十章实践——系统级I/O代码运行
第十章实践——系统级I/O代码运行 实验代码清单如下: 1. cp1——复制一个文件到另一个文件中(两个已经存在的文件) 复制前: 执行后结果 2. setecho.echostate——改变.显示输 ...