推理可得终于结果为2的(n-可分组合数)次方。

问题是怎么求出可分组合数,深搜就可以,当然并查集也能够。

AC代码例如以下:

深搜代码!!!

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define M 100005
#define ll long long
using namespace std; int a,b,c[205][205],vis[205];
int n,m; void dfs(int x)
{
int i;
vis[x]=1;
for(i=1;i<=n;i++)
{
if(!vis[i]&&c[x][i])
dfs(i);
}
} int main()
{ int i,j;
int sum,ans=0;
cin>>n>>m;
memset(c,0,sizeof c);
memset(vis,0,sizeof vis);
for(i=0;i<m;i++)
{
cin>>a>>b;
c[a][b]=1;
c[b][a]=1;//将a,b关联,能够用容器。但我认为不是必需
}
if(m==0)
cout<<"1"<<endl;
else{
for(j=1;j<=n;j++)
{
if(!vis[j])
{dfs(j);ans++;}//从一点搜起。记录组合数
}
cout<<(1LL<<(n-ans))<<endl;
} return 0;
}

并查集代码!!





#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std; int f[50005],vis[50005];
int find (int x)
{
if(f[x]==x)
return f[x];
else return find(f[x]);
} int main()
{
int n,m;
int i,j;
int a,b,c; long long ans;
cin>>n>>m;
memset(vis,0,sizeof vis);
ans=0;
for(i=1;i<=n;i++)
f[i]=i;
for(i=1;i<=m;i++)
{
cin>>a>>b;
a=find (a);
b=find (b);
f[a]=b;
}
for(i=1;i<=n;i++)
{
c=find(i);
if(!vis[c])
{ans++;vis[c]=1;}
}
cout<<(1LL<<(n-ans))<<endl;
return 0;
}

Codeforces Round #254 (Div. 2) B (445B)DZY Loves Chemistry的更多相关文章

  1. Codeforces Round #254 (Div. 2)D(预计)

    D. DZY Loves FFT time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  2. Codeforces Round #306 (Div. 2) ABCDE(构造)

    A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全, ...

  3. Codeforces Round #309 (Div. 1) A(组合数学)

    题目:http://codeforces.com/contest/553/problem/A 题意:给你k个颜色的球,下面k行代表每个颜色的球有多少个,规定第i种颜色的球的最后一个在第i-1种颜色的球 ...

  4. Codeforces Round #392(Div 2) 758F(数论)

    题目大意 求从l到r的整数中长度为n的等比数列个数,公比可以为分数 首先n=1的时候,直接输出r-l+1即可 n=2的时候,就是C(n, 2)*2 考虑n>2的情况 不妨设公比为p/q(p和q互 ...

  5. Codeforces Round #532 (Div. 2)- B(思维)

    Arkady coordinates rounds on some not really famous competitive programming platform. Each round fea ...

  6. Codeforces Round #597 (Div. 2)D(最小生成树)

    /*每个点自己建立一座发电站相当于向超级源点连一条长度为c[i]的边,连电线即为(k[i]+k[j])*两点间曼哈顿距离,跑最小生成树(prim适用于稠密图,kruscal适用于稀疏图)*/ #def ...

  7. Codeforces Round #327 (Div. 2)B(逻辑)

    B. Rebranding time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  8. Codeforces Round #207 (Div. 1)B(数学)

    数学so奇妙.. 这题肯定会有一个循环节 就是最小公倍数 对于公倍数内的相同的数的判断 就要借助最大公约数了 想想可以想明白 #include <iostream> #include< ...

  9. Hot Days Codeforces Round #132 (Div. 2) D(贪婪)

    Description The official capital and the cultural capital of Berland are connected by a single road ...

随机推荐

  1. 日志组件Log4Net

    <?xml version="1.0" encoding="utf-8"?> <configuration> <configSec ...

  2. 《Linux命令、编辑器与shell编程》第三版 学习笔记---003 使用multibootusb

    1.下载文件https://codeload.github.com/mbusb/multibootusb-8.9.0.tar.gz,使用命令: tar xvf multibootusb-8.9.0.t ...

  3. linux系统调用实现代码分析【转】

    转自:http://linux.chinaunix.net/doc/kernel/2001-07-30/637.shtml 启动早就读完,现在为了写笔记再从启动之后粗略的大体读一遍,基本就是几个大模块 ...

  4. C程序编译过程浅析【转】

    转自:http://blog.csdn.net/koudaidai/article/details/8092647 前几天看了<程序员的自我修养——链接.装载与库>中的第二章“编译和链接” ...

  5. 使用MyQR生成二维码

    from MyQR import myqr # 主要用到以下几个参数 # words:文本,可以是一个链接,或者你想说的话 # picture:你用到的图片,作为背景,不然只是一个光秃秃的二维码 # ...

  6. Windows8 上用Ubuntu-Ubuntu启动SSH

    公司刚给配了一个电脑,华硕的超级本8个G的内存,很强大的了,但是系统是64位的windows 8,我用wubi.exe直接安装到系统上,但是开机启动的时候总是下面这个错误,去Ubuntu社区请教,结论 ...

  7. centos6.5 安装mysql

    在centos6.5上通过yum安装mysql: 1. yum list |grep mysql   (查看版本) 2.安装mysql yum install -y mysql-server mysq ...

  8. 【linux高级程序设计】(第十一章)System V进程间通信 1

    System V, 曾经也被称为 AT&T System V,是Unix操作系统众多版本中的一支. 传统上,System V 被看作是两种UNIX"风味"之一(另一个是 B ...

  9. Curl请求方法封装

    /** * GET请求 * @param $url * @return bool|mixed */ function http_get($url) { $oCurl = curl_init (); i ...

  10. 51nod 1182 完美字符串【字符串排序+哈希】

    1182 完美字符串 题目来源: Facebook Hacker Cup选拔 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题  收藏  关注 约翰认为字符串的完美度等 ...