注意题目条件!!! 团问题 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了十多发,后来看了别人的题解,思路是一样的,他做了剪枝的我也做了,为何他的能过的我的超时?后来发现一个不是主要问题的问题:大家的图存储用的都是前向 ...
随机推荐
- javaWEB总结(10):HttpServlet成长史
前言: 从Servlet,ServletConfig到GenericServlet再到Httpservlet的整个过程,相当于Httpservlet的成长史,我们不需要写那么臃肿的代码,开发难度由复杂 ...
- System.InvalidOperationException nested transactions are not supported
如下bll方法,在执行时会报事务嵌套异常.bll方法里开启了分布式事务,dal方法里又启动了数据库事务.通过查看异常堆栈,发现异常是在执行BillsDal.Add(bill);方法里的var tran ...
- WebService第二天
WebService第二天 课程安排:(CXF+HESSIAN) 框架CXF概述(是什么,SOA概述,下载安装) CXF快速入门(服务端.客户端开发,日志拦截器,SOAP版本相互调用的) CXF与sp ...
- js--闭包的理解
从技术上来讲,在JS中,每个function都是闭包,因为它总是能访问在它外部定义的数据. 当该内部函数在外部函数外被调用,就生成了闭包. 函数内部可以直接读取全局变量. 闭包就是能够读取其他函数内部 ...
- hancher57公众号突破3000人
- POJ 1740 A New Stone Game(多堆博弈找规律)
传送门 //有n堆,AB轮流从n堆的一堆中移任意个,可以扔掉,也可以移给其他堆中的一堆 //最先移完的胜 //如果n堆中两两堆数目相等,那肯定是B胜 //但只要有非两两相同的,如xyz,A先, //A ...
- POJ 1862 Stripies#贪心(水)
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<cmath> #include<algorithm ...
- Highest Rated Features
- 驱动力—— 通信引擎(上)—— ESFramework 4.0 进阶(03)
在ESFramework 4.0 进阶(02)-- 核心:消息处理的骨架流程一文中我们详细介绍了ESFramework中消息处理的骨架流程,并且我们已经知道,ESFramework中的所有通信引擎使用 ...
- [ An Ac a Day ^_^ ] CodeForces 680A Bear and Five Cards
这两天回家了 家里电脑太卡 调试不方便 就只能写写水题了…… #include<stdio.h> #include<iostream> #include<algorith ...