题目大意:团的定义就是,团内的所有点,两两之间各有一条边,团的大小就是点的个数。现给你一个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. c#委托与事件(详解)

    引言 委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真是太容易了,而没有过去 ...

  2. 用户代理检测与浏览器Ua详细分析

    用户代理检测与浏览器Ua详细分析:http://www.cnblogs.com/hykun/p/Ua.html

  3. Sass与Compress实战:第四章

    概要:这一章将深挖Compass的工具箱,看看Compass的混合器如何帮助你省去编写重复样式表的辛苦工作. 本章内容: ● 使用Compass重置浏览器默认样式表 ● 改进样式表排版的Compass ...

  4. hdu_5826_physics(物理题)

    题目链接:hdu_5826_physics 题意: 给你一些点的速度和初始位置,还有方向,这些速度和加速度满足v*a=c,然后又q个询问,问第t秒第K小的速度是多少 题解: 将物理公式转换为v与t的关 ...

  5. Hihocoder 2月29日

      时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 只有闰年有2月29日,满足以下一个条件的年份为闰年 ...

  6. 有关app的一些小知识

    META相关 1. 添加到主屏后的标题(IOS)<meta name="apple-mobile-web-app-title" content="标题"& ...

  7. 【Linux】zookeeper构造伪集群

    1.在一台机器装安装3个zk server,构建伪集群模式安装步骤如下:1.下载zookeeper,下载地址:http://mirror.bit.edu.cn/apache/zookeeper/zoo ...

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

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

  9. CSS的基本概念

    <!--CSS 一.概念:CSS的全称是Cascading Style Sheets,层叠样式表,用来控制HTML标签样式,在美化网页中起到非常重要的作用 CSS的编写格式是键值对形式的,比如 ...

  10. 与导航栏下控件的frame相关的edgesForExtendedLayout、translucent、extendedLayoutIncludesOpaqueBars、automaticallyAdjustsScrollViewInsets等几个属性的详解

    在引入了导航控制器UINavigationController和分栏控制器UITabBarController之后,我们在设置控件的frame的时候就需要注意避开导航栏UINavigationBar ...