题目大意:团的定义就是,团内的所有点,两两之间各有一条边,团的大小就是点的个数。现给你一个n个点,m条边的图。问,该图中有多少点的个数为s的团。

(题目保证每个点的度数不超过20,n<=100, m<=1000, s<=10)

思路:由于度数不超过20,那么最多就是C20取9,于是我们暴力枚举一下就好了。然后在代码中,我规定,邻接表G[U]里面的元素,都是u<v的。

//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker,"/STACK:102400000,102400000")
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha printf("haha\n")
const int maxn = + ;
vector<int> G[maxn];
bool atlas[maxn][maxn];
int a[maxn];
int n, m, s; int dfs(int u, int pos, int cnt, int s){
if (cnt == s) {
return ;
}
int ans = ;
for (int i = pos; i < G[u].size(); i++){
int v = G[u][i];
bool flag = true;
for (int j = ; j <= cnt; j++){
if (!atlas[a[j]][v]) {flag = false; break;}
}
if (!flag) continue;
a[cnt + ] = v;
ans += dfs(u, i + , cnt + , s);
}
return ans;
} int solve(){
vector<int> ds;
for (int i = ; i <= n; i++){
if (G[i].size() >= s - ) ds.pb(i);
}
int ans = ;
for (int i = ; i < ds.size(); i++){
int u = ds[i];
a[] = u;
for (int j = ; j < G[u].size(); j++){
int v = G[u][j];
a[] = v;
ans += dfs(u, j + , , s);
}
}
return ans;
} int main(){
int t; cin >> t;
while (t--){
scanf("%d%d%d", &n, &m, &s);
for (int i = ; i <= n; i++) G[i].clear();
memset(atlas, , sizeof(atlas));
for (int i = ; i <= m; i++){
int u, v; scanf("%d%d", &u, &v);
if (atlas[u][v]) continue;
atlas[u][v] = , atlas[v][u] = ;
if (u > v) swap(u, v);
G[u].pb(v);
}
printf("%d\n", solve());
}
return ;
}

注意题目条件!!! 团问题 HDU 5952的更多相关文章

  1. HDU - 5952 Counting Cliques

    Counting Cliques HDU - 5952 OJ-ID: hdu-5952 author:Caution_X date of submission:20191110 tags:dfs,gr ...

  2. hdu 5952 Counting Cliques 求图中指定大小的团的个数 暴搜

    题目链接 题意 给定一个\(n个点,m条边\)的无向图,找出其中大小为\(s\)的完全图个数\((n\leq 100,m\leq 1000,s\leq 10)\). 思路 暴搜. 搜索的时候判断要加进 ...

  3. HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)

    Counting Cliques Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  4. HDU 5952 [DFS]

    题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=5952] 题意:给出一张无向图,然后判断这张图中一共有多少个不同的大小为S的完全图,并且保证每个点的度 ...

  5. Counting Cliques HDU - 5952 单向边dfs

    题目:题目链接 思路:这道题vj上Time limit:4000 ms,HDU上Time Limit: 8000/4000 MS (Java/Others),且不考虑oj测评机比现场赛慢很多,但10月 ...

  6. hdu 5952 连通子图

    Counting Cliques Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  7. HDU - 5952 Counting Cliques(dfs搜索)

    题目: A clique is a complete graph, in which there is an edge between every pair of the vertices. Give ...

  8. 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 ...

  9. 关于HDU 5952的那些事

    内容过后再贴,先发表一下心情和感悟. 这个题,我TLE了十多发,后来看了别人的题解,思路是一样的,他做了剪枝的我也做了,为何他的能过的我的超时?后来发现一个不是主要问题的问题:大家的图存储用的都是前向 ...

随机推荐

  1. 淘淘商城_day01_课堂笔记

    今日大纲 聊聊电商行业 电商行业发展 11.11 2015双11: 2016年: 预测:2017年的双11交易额将达到:1400亿 电商行业技术特点 淘淘商城简介 淘淘商城的前身 电商行业的概念 B2 ...

  2. HDU 1054 Strategic Game(无向二分图的最大匹配)

    ( ̄▽ ̄)" //凡无向图,求匹配时都要除以2 #include<iostream> #include<cstdio> #include<algorithm&g ...

  3. poj_1743_Musical Theme(后缀数组)

    题目链接:poj_1743_Musical Theme 题意: 给你一串数字,让你找最长的变化相同不重叠的子串,至少长度为5 题解: 处理数据后用后缀数组加二分答案,然后用height数组check答 ...

  4. strpos 返回0时 ,比较false 不能加单引号

    $a =  'a.approve'; $num = strpos($a,'a.admin'); if(strpos($a,'a.approve') !== 'false'){ //不能加单引号.变字符 ...

  5. agentX各个角色功能

    AgentX Roles  1.master An entity acting in a master agent role performs the following  functions: -  ...

  6. Zmodem协议

    Zmodem文件传输协议 做zeppelin测试时,自己安装了虚拟机,发现一个在linux和windows之间特别方便的命令行rz/sz工具. Install # 由于虚拟机不能上网,所以先挂载镜像. ...

  7. VC 中使用 CToolTipCtrl 消失后不再出现的Bug。。。。

    最近用WTL重写CGdipButton.从ButtonST中将CtoolTipCtrl的相关代码转过来,发现一个问题: ToolTip可以显示,鼠标移开后再移动到button上也可以再次显示,但是按下 ...

  8. MySQL5.6新特性Index conditontion pushdow

    index condition pushdown是MySQL5.6的新特性,主要是对MySQL索引使用的优化. Index condition push简称ICP,索引条件下推,将索引条件从serve ...

  9. SSL+socket详解

    转自:http://hengstart.iteye.com/blog/842529 一.        SSL概述 SSL协议采用数字证书及数字签名进行双端实体认证,用非对称加密算法进行密钥协商,用对 ...

  10. 不安装oracle客户端,如何运行sqlplus

    1.软件下载 http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html 下载如下三个包: oracle-instantc ...