HDU - 5952 Counting Cliques
Counting Cliques
OJ-ID:
hdu-5952
author:
Caution_X
date of submission:
20191110
tags:
dfs,graph
description modelling:
给定点数,边数,问包含有x个点的完全图种类数
major steps to solve it:
(1)选择一个点作为起点,记录该起点的所有连通点,dfs(该点)此时完全图有两个点
(2)遍历(1)中选定点的连通点,若构成完全图,则dfs(能够与(1)的图构成完全图的点)此时完全图有三个点 以此类推 当完全图点数=x时结束dfs
(3)重复(2)操作直到所有点都被作为起点使用过
warnings:
因为每一个起点都满足含有[2,x]个点的完全图,因此,不同起点达到x个点时的完全图相互独立
AC code:
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<bitset>
using namespace std;
const int maxn = ;
int s,ans;
bool mp[maxn][maxn];
/*
这里的dfs看起来很简单,其实包含了一个很大的剪枝:在遍历某个点的时候,已经确定了已经加入团的点是与这个点相连的,还可以知道平均下来每个点的入度不会超过20,
因此整个遍历的复杂度最高是C(9,20)*100
*/
void dfs(int mx,int v[],int cnt){
int nxt[maxn];
if(cnt==s) {ans++;return;}
for(int i=;i<mx;i++){ //枚举能与点数为cnt的团构成点数为cnt+1的团的所有点
int len=;
for(int j=i+;j<mx;j++){
if(mp[v[i]][v[j]]){ //该团的所有"候选点"必须与已经选了的点相连
nxt[len++]=v[j];
}
}
dfs(len,nxt,cnt+);
}
}
int main(){
int T,n,m,u,v;
// freopen("in.txt","r",stdin);
scanf("%d",&T);
while(T--){
scanf("%d%d%d",&n,&m,&s);
memset(mp,,sizeof(mp));
for(int i=;i<m;i++){
scanf("%d%d",&u,&v);
mp[u][v]=mp[v][u]=;
}
ans=;
int nxt[];
for(int i=;i<=n;i++){ //枚举每个点,这个点必须在所求的团里面,以这个点开始搜索
int len=;
for(int j=i+;j<=n;j++){
if(mp[i][j]){ //该团的所有"候选点"必须与已经选了的点相连
nxt[len++]=j;
}
}
dfs(len,nxt,);
}
printf("%d\n",ans);
}
return ;
}
HDU - 5952 Counting Cliques的更多相关文章
- HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)
Counting Cliques Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 5952 Counting Cliques(dfs)
Counting Cliques Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU - 5952 Counting Cliques(DFS)
A clique is a complete graph, in which there is an edge between every pair of the vertices. Given a ...
- HDU - 5952 Counting Cliques(dfs搜索)
题目: A clique is a complete graph, in which there is an edge between every pair of the vertices. Give ...
- hdu 5952 Counting Cliques 求图中指定大小的团的个数 暴搜
题目链接 题意 给定一个\(n个点,m条边\)的无向图,找出其中大小为\(s\)的完全图个数\((n\leq 100,m\leq 1000,s\leq 10)\). 思路 暴搜. 搜索的时候判断要加进 ...
- hdu 5862 Counting Intersections
传送门:hdu 5862 Counting Intersections 题意:对于平行于坐标轴的n条线段,求两两相交的线段对有多少个,包括十,T型 官方题解:由于数据限制,只有竖向与横向的线段才会产生 ...
- HDU 5862 Counting Intersections(离散化+树状数组)
HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...
- 【算法系列学习】巧妙建图,暴搜去重 Counting Cliques
E - Counting Cliques http://blog.csdn.net/eventqueue/article/details/52973747 http://blog.csdn.net/y ...
- hdu 5952 连通子图
Counting Cliques Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
随机推荐
- 【朝花夕拾】Android多线程之(三)runOnUiThread篇——程序猿们的贴心小棉袄
runOnUiThread()的使用以及原理实在是太简单了,简单到笔者开始都懒得单独开一篇文章来写它.当然这里说的简单,是针对对Handler比较熟悉的童鞋而言的.不过麻雀虽小,五脏俱全,runOnU ...
- Python爬虫基础——re模块的提取和匹配
re是Python的一个第三方库. 为了能更直观的看出re的效果,我们先新建一个HTML网页文件(可直接复制): index.html <!DOCTYPE html> <html l ...
- spf13-vim安装成功
之前安装好像都没有出现这个画面,说明我安装得不完整吧!有一个html括号匹配的插件要求输入username和password,不知所以然,没安装上,其他应该一切正常.纪念一个!
- django生命周期请求l流程图
django思维导图链接:https://www.processon.com/view/link/5dddb0f8e4b074c442e5c68c
- 深入理解this原理(JavaScript)
文章目录 JavaScript中this的原理 一.问题的由来 二.内存的数据结构 三.函数 四.环境变量 JavaScript中this的原理 一.问题的由来 学懂 JavaScript 语言,一个 ...
- [译]C# 7系列,Part 6: Read-only structs 只读结构
原文:https://blogs.msdn.microsoft.com/mazhou/2017/11/21/c-7-series-part-6-read-only-structs/ 背景 在.NET世 ...
- openresty安装配置
在centos7上操作的. 上周搞了两天的Nginx的location rewrite,突然,对Nginx有了更好的理解. 所以持续一下. yum install readline-devel pcr ...
- Nacos Cluster Building
原文链接:https://www.javaspring.net/nacos/nacos-cluster-building Continue to talk about the Nacos build ...
- WPF 3D球及进阶玩法
在WPF中3D球的构建算法请参考: https://www.cnblogs.com/lonelyxmas/p/9844951.html 好玩以及值得借鉴的Demo: (CSDN下载需要积分,避免你 ...
- 如何修改CAD字体颜色?试试这种方法
CAD中编辑图纸的时候,使用的CAD制图软件来进行绘制,图纸中的CAD字体颜色都是默认的颜色,这样不方便进行查看.这个时候就需要修改CAD字体颜色了,那么如何修改CAD字体颜色呢?具体要怎么来进行操作 ...