题目大意:团的定义就是,团内的所有点,两两之间各有一条边,团的大小就是点的个数。现给你一个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. team viewer - rollback framework could not be initialized

    rollback framework could not be initialized, 在安装team viewer 的时候出现的这个错误信息,求大师帮忙 https://zhidao.baidu. ...

  2. magento寄存器的使用

    1.Mage::register('validation_image_name', $validationImageName);//这个是把变量$validationImageName存储在valid ...

  3. hdu_5354_Bipartite Graph(cdq分治+并查集判二分图)

    题目链接:hdu_5354_Bipartite Graph 题意: 给你一个由无向边连接的图,问对于每一个点来说,如果删除这个点,剩下的点能不能构成一个二分图. 题解: 如果每次排除一个点然后去DFS ...

  4. git上传代码到github

    git上传代码到github [root@bigdata-hadoop- ~]# git init [root@bigdata-hadoop- ~]# git add zeppelin [root@b ...

  5. HTML5 学习总结

    1,h5比原来的h4.0版本的页面头部更为简化, <!doctype html> <meta charset="utf-8"/>sublime中快速生成格式 ...

  6. SHELL自动运行脚本

    pass.sh ------------------------ #!/bin/bashecho start /usr/bin/expect <<EOFset timeout 10spaw ...

  7. idea 注册码

    生成地址:http://idea.lanyus.com/ ------------------------------------- IntelliJ IDEA 注册码 *.lanyus.com及*. ...

  8. kissy小记

    <script> KISSY.add('demo',function(S ,require, exports, module){ var Node = require('node'); v ...

  9. 一个文字无缝滚动的jQuery插件

    直接上代码吧 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. ...

  10. ***1133. Fibonacci Sequence(斐波那契数列,二分,数论)

    1133. Fibonacci Sequence Time limit: 1.0 secondMemory limit: 64 MB is an infinite sequence of intege ...