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) ...
随机推荐
- 【Activiti】使用学习
[Activiti]使用学习 转载: ================================================== 1.下载安装 2.清空表 3.开启sql打印 4. 5. = ...
- drf源码分析系列---权限
权限的使用 全局使用 from rest_framework.permissions import BasePermission from rest_framework import exceptio ...
- js prop方法
添加和删除属性 $("button").click(function(){ var $x = $("div"); <!--添加属性--> $x.pr ...
- 稳定易用的 Django 分页库,完善分页功能
作者:HelloGitHub-追梦人物 文中所涉及的示例代码,已同步更新到 HelloGitHub-Team 仓库 在 通过 Django Pagination 实现简单分页 中,我们实现了一个简单的 ...
- 基于ATxmega128的ASF串口应用
1.编辑串口的配置参数,一般将这些参数放在conf_usart.h配置头文件中,本程序将这些参数放在user_board.h头文件中 #define USART_SERIAL &USARTD0 ...
- Provider模式应用demo
参考ObjectPool对象池设计原理还原一个简易的Provider模式. using System; using System.Dynamic; using System.Reflection.Me ...
- HttpRunner学习10--hook机制
前言 对于使用过 Python结合Unittest 框架来做自动化测试的同学,应该知道在 Unittest 中,有这样2个方法:setUp() 和 tearDown() ,即前置和后置操作.通常 se ...
- CURL命令学习二
-a, --append 用于上传文件时,如果服务器上该文件不存在则创建,如果存在则追加到源文件. -K, --config <file> 指定从某个文件读取curl参数.如果指定-为文件 ...
- supervisor 相关命令
今天重新使用 supervisor 相关命令的时候,发现已经忘了,下面重新进行记录一下,进行备忘: supervisorctl restart <application name> ; 重 ...
- Linux修改History历史命令数量
****打开 vim /etc/profile vim /etc/profile 追加配置 # /etc/profile: system-wide .profile file for the B ...