推理可得终于结果为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. 制定ip池内随机生成ip地址

    ]) { +] = {}; unsigned mask = 0x0; sscanf(ip_pool, "%[^/]/%d", ip_addr, &mask); long l ...

  2. jsp/el和jstl动态页面

    一.JSP技术 1.jsp脚本和注释 jsp脚本: 1)<%java代码%> ----- 内部的java代码翻译到service方法的内部 2)<%=java变量或表达式> - ...

  3. React+dva.js+typescript实现百度贴吧移动web端

    个人练习作品,有bug欢迎在github上提:) github地址:https://github.com/axel10/react-tieba 整个项目中实现起来最麻烦的应该算是滚动位置记忆和路由动画 ...

  4. Python_Tips[6] -> is 和 == 的区别

    is和==的区别 / Difference between is and == 对于Python的对象来说,具有id/type/value三种特性,而在判断两个相等的is和==中,分别是对对象的id和 ...

  5. springboot引入thymeleaf

    springboot引入thymeleaf 1.Thymeleaf使用 @ConfigurationProperties(prefix = "spring.thymeleaf") ...

  6. Lowest Common Ancestor of a Binary Search Tree -- LeetCode

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  7. [BZOJ 4031] 小Z的房间

    Link: BZOJ 4031 传送门 Solution: 矩阵树定理的模板题 看完下面两篇文章就会啦: 周冬论文:https://wenku.baidu.com/view/872eb02de2bd9 ...

  8. 数论day1 —— 基础知识(们)

    [pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=61632537 向大(hei)佬(e)势力学(di ...

  9. 代理模式(Proxy)--静态代理

    1,代理模式的概念 代理模式:为其他对象提供一种代理,以控制对这个对象的访问(代理对对象起到中介的作用,可去掉功能服务或者添加额外的服务) 2,代理模式的分类 (1)远程代理:类似于客户机服务器模式 ...

  10. 解魔方的机器人攻略14 – 安装Lejos(下)

    由 动力老男孩 发表于 2009/12/27 17:16:11 第四步:安装Lejos 登陆 Lejos 主页点击 NXT 图片进入 Lejos 下载页面,点击 NXJ 的下载链接: 下载完成后将下载 ...