注意题目条件!!! 团问题 HDU 5952
题目大意:团的定义就是,团内的所有点,两两之间各有一条边,团的大小就是点的个数。现给你一个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的更多相关文章
- HDU - 5952 Counting Cliques
Counting Cliques HDU - 5952 OJ-ID: hdu-5952 author:Caution_X date of submission:20191110 tags:dfs,gr ...
- hdu 5952 Counting Cliques 求图中指定大小的团的个数 暴搜
题目链接 题意 给定一个\(n个点,m条边\)的无向图,找出其中大小为\(s\)的完全图个数\((n\leq 100,m\leq 1000,s\leq 10)\). 思路 暴搜. 搜索的时候判断要加进 ...
- 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 [DFS]
题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=5952] 题意:给出一张无向图,然后判断这张图中一共有多少个不同的大小为S的完全图,并且保证每个点的度 ...
- Counting Cliques HDU - 5952 单向边dfs
题目:题目链接 思路:这道题vj上Time limit:4000 ms,HDU上Time Limit: 8000/4000 MS (Java/Others),且不考虑oj测评机比现场赛慢很多,但10月 ...
- hdu 5952 连通子图
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. Give ...
- 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的那些事
内容过后再贴,先发表一下心情和感悟. 这个题,我TLE了十多发,后来看了别人的题解,思路是一样的,他做了剪枝的我也做了,为何他的能过的我的超时?后来发现一个不是主要问题的问题:大家的图存储用的都是前向 ...
随机推荐
- 整屏滚动效果 jquery.fullPage.js插件+CSS3实现
最近很流行整屏滚动的效果,无论是在PC端还是移动端,本人也借机学习了一下,主要通过jquery.funnPage.js插件+CSS3实现效果. 本人做的效果: PC端:http://demo.qpdi ...
- 第九十六节,JavaScript概述
JavaScript概述 学习要点: 1.什么是JavaScript 2.JavaScript特点 3.JavaScript历史 4.JavaScript核心 5.开发工具集 JavaScript诞生 ...
- 2-jQuery - AJAX load() 方法【进阶篇】
第一篇的AJAX load() 方法过于简单,补充一下,完整的. 格式 $(selector).load(URL,data,callback); 源码 <!DOCTYPE html> &l ...
- hdu_5969_最大的位或(贪心)
题目链接:hdu_5969_最大的位或 题意: 中文,还是自己看 题解: xjb贪心一下就行了 #include<bits/stdc++.h> #define F(i,a,b) for(i ...
- ajax格式,需要指定交互的data类型
思路 先打印所有返回值 console.log(d); {''status'':999} 再查看返回值,能否转换为json dataType:'json', //大小写敏感. datatype ...
- 分布式事务、XA、两阶段提交、一阶段提交
本文原文连接:http://blog.csdn.net/bluishglc/article/details/7612811 ,转载请注明出处! 1.XA XA是由X/Open组织提出的分布式事务的规范 ...
- 关于springboot启动时候报错:springboot Failed to parse configuration class [Application]
把运行的java类放在一个package下后就不再提示这个错误. 使用的ide是intellij,之前也有因为没有创建package报错的经历,可能这是intellij必须的
- css实现多行超出显示省略号?
可以实现,但是用的是-webkit-私有属性.我用js已经解决了.代码如下:text-overflow: -o-ellipsis-lastline;overflow: hidden;text-over ...
- Python 学习笔记3
人如果从来没有怀疑过自己,那他永远都不会进步. 今天学习Python解释器及其环境. http://www.pythondoc.com/pythontutorial3/interpreter.html
- [转载]The Island Castaway mac版解锁
http://blog.sina.com.cn/s/blog_506b3ac90101ke0e.html 1.首先,去安装一个The Island - Castaway™ mac free版,然后打开 ...