HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)
Counting Cliques
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 539 Accepted Submission(s): 204Problem DescriptionA clique is a complete graph, in which there is an edge between every pair of the vertices. Given a graph with N vertices and M edges, your task is to count the number of cliques with a specific size S in the graph.InputThe first line is the number of test cases. For each test case, the first line contains 3 integers N,M and S (N ≤ 100,M ≤ 1000,2 ≤ S ≤ 10), each of the following M lines contains 2 integers u and v (1 ≤ u < v ≤ N), which means there is an edge between vertices u and v. It is guaranteed that the maximum degree of the vertices is no larger than 20.OutputFor each test case, output the number of cliques with size S in the graph.Sample Input3
4 3 2
1 2
2 3
3 4
5 9 3
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5
6 15 4
1 2
1 3
1 4
1 5
1 6
2 3
2 4
2 5
2 6
3 4
3 5
3 6
4 5
4 6
5 6Sample Output3
7
15SourceRecommendjiangzijing2015 | We have carefully selected several similar problems for you: 5960 5959 5958 5957 5956
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5952
题目大意:
给N个点M条边,求大小位S的集合的个数,要求集合内的元素两两有边(完全图)。
题目思路:
【DFS+剪枝】
每个点最多20条出边。暴力。
首先去掉边数<S-1的点,枚举剩下的X,枚举完X可以把X的所有边删掉。加几个小剪枝即可。
//
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-8)
#define J 10000
#define mod 2147493647
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 104
#define M 2004
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans,sz;
int last[N];
struct xxx
{
int next,to;
}a[M];
int b[N],c[N],in[N];
void add(int x,int y)
{
a[++sz].next=last[x];
a[sz].to=y;
last[x]=sz;
}
bool ma[N][N];
void dfs(int top,int now)
{
if(top-+lll-now<cas)return;
if(top==cas+)
{
ans++;
return;
}
int i,j,to;
for(i=last[now];i;i=a[i].next)
{
to=a[i].to;
if(!ma[c[now]][c[to]] || to<now)continue;
for(j=;j<top;j++)
if(!ma[c[to]][b[j]])break;
if(j<top)continue;
b[top]=to;
dfs(top+,to);
b[top]=;
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,z;
// init();
for(scanf("%d",&cass);cass;cass--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
// while(~scanf("%d%d",&n,&m))
{
mem(ma,);mem(in,);mem(last,);ans=;lll=;sz=;
scanf("%d%d%d",&n,&m,&cas);
for(i=;i<=m;i++)
{
scanf("%d%d",&x,&y);
in[x]++,in[y]++;
ma[x][y]=ma[y][x]=;
}
for(i=;i<=n;i++)
if(in[i]>=cas-)
c[++lll]=i;
for(i=;i<=lll;i++)
for(j=i+;j<=lll;j++)
if(ma[c[i]][c[j]])
add(i,j);
for(i=;i<=lll;i++)
{
b[]=c[i];
dfs(,i);
for(j=last[c[i]];j;j=a[j].next)
ma[c[a[j].to]][c[i]]=ma[c[i]][c[a[j].to]]=;
}
printf("%d\n",ans);
}
return ;
}
/*
// //
*/
HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)的更多相关文章
- hdu 5510 Bazinga (kmp+dfs剪枝) 2015ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)
废话: 这道题很是花了我一番功夫.首先,我不会kmp算法,还专门学了一下这个算法.其次,即使会用kmp,但是如果暴力枚举的话,还是毫无疑问会爆掉.因此在dfs的基础上加上两次剪枝解决了这道题. 题意: ...
- HDU 5950 Recursive sequence 【递推+矩阵快速幂】 (2016ACM/ICPC亚洲区沈阳站)
Recursive sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- HDU 5948 Thickest Burger 【模拟】 (2016ACM/ICPC亚洲区沈阳站)
Thickest Burger Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 5949 Relative atomic mass 【模拟】 (2016ACM/ICPC亚洲区沈阳站)
Relative atomic mass Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- HDU 5976 Detachment 【贪心】 (2016ACM/ICPC亚洲区大连站)
Detachment Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- HDU 5979 Convex【计算几何】 (2016ACM/ICPC亚洲区大连站)
Convex Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- HDU 6225.Little Boxes-大数加法 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))
整理代码... Little Boxes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/O ...
- 2016ACM/ICPC亚洲区沈阳站 - A/B/C/E/G/H/I - (Undone)
链接:传送门 A - Thickest Burger - [签到水题] ACM ICPC is launching a thick burger. The thickness (or the heig ...
- 2016ACM/ICPC亚洲区沈阳站 Solution
A - Thickest Burger 水. #include <bits/stdc++.h> using namespace std; int t; int a, b; int main ...
随机推荐
- MAC itunes无法验证服务器s.mzstatic/itunes无法更新服务器解决方案
打开host文件: 一.用终端打开: sudo vi /etc/hosts 输入完这行命令后需要输入电脑密码,然后确认,进入host文件 然后按i键进入编辑模式,在最后一行添加:23.214.233. ...
- hbuider 中点击就显示出一个单选的列表 ,然后后台跨域向里面动态添加数据,注意里面的格式是json object
jsp页面: <li class="mui-table-view-cell" onclick="showActionSheet()"> <di ...
- Linux调整SWAP分区
刪除原swap分區,重建swap,步驟如下:1,swapoff -a #停止交換分區2,fdisk /dev/sda #進入fdisk,刪除原swap分區,重新建立新分區(swap分區的系統ID是82 ...
- Python全栈开发-web框架之django
一:web框架 什么是web框架? Web应用框架(Web application framework)是一种开发框架,用来支持动态网站.网络应用程序及网络服务的开发.这种框架有助于减轻网页开发时共通 ...
- git push用法和常见问题分析
在使用git 处理对android的修改的过程之中总结的.但不完善 Git push $ git push origin test:master // 提交本地test分支作为远程的m ...
- C++中弱符号(弱引用)的意义及实例
今天读别人代码时看到一个“#pragma weak”,一时没明白,上网研究了一个下午终于稍微了解了一点C.C++中的“弱符号”,下面是我的理解,不正确的地方望大家指正. 本文主要从下面三个方面讲“弱符 ...
- AOP和IOC理解
在百度上看到一篇很有意思的文章,是对AOP的一种解释,如下:(摘自:百度文库的 AOP和IOC最容易理解的说明(Spring知识小计)): IOC,依赖倒置的意思, 所谓依赖,从程序的角度看,就是比如 ...
- Aircrack-ng官方文档翻译[中英对照]---Airmon-ng
Aircrack-ng官方文档翻译---Airmon-ng Description[简介] This script can be used to enable monitor mode on wire ...
- jquery点击图片选中特效
jquery点击图片选中特效 点击在线预览效果
- leetcode第八题 String to Integer (atoi) (java)
String to Integer (atoi) time=272ms accepted 需考虑各种可能出现的情况 public class Solution { public int atoi( ...