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 ...
随机推荐
- JS获取日期和时间
//获取日期和时间 function showDate(){ var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFul ...
- Ubuntu 使用top/free查看内存占用大的原因
Ubuntu 使用top/free查看内存占用大的原因 linux/ubuntu下free/top查看内存占用大的原因 使用free/top查看内存占用的时候,吓了一大跳,机器4GB的内存,显 ...
- javascript中event.keycode大全
keycode 8 = BackSpace BackSpace keycode 9 = Tab Tab keycode 12 = Clear keycode 13 = Enter keycod ...
- javaScripte 创建对象。。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- cocos2d-x使用DragonBones动画
前言 在网上查找关于DragonBones在cocos2d-x的使用教程,找了大半天也没有找到一个有用的.在自己摸索了一段时间终于摸索了出来,在这里记下分享给大家. 下载DragonBones 我这里 ...
- 代码方式删除SVN
public static void delect(File s) { File b[] = null; if (s.exists()) {// 判读是否存在 if (s.isDirectory()) ...
- github 查看单个文件的历史记录命令
gitk 安装: apt-get install gitk 点击打开链接http://stackoverflow.com/questions/278192/view-the-change-histor ...
- 青瓷qici - H5小游戏 抽奖机 3 效果设置
现在是万事俱备,只欠东风,好,我们一起动手,先来东风东. 烟花粒子效果 第一个来实现我们的烟花粒子效果,点击我们的粒子,按照下图方式配置. 注意此时我们已经加入了white.png作为粒子特效使用. ...
- JavaScript经典面试题系列
1.javascript的typeof返回哪些数据类型 Object number function boolean underfind 2.例举3种强制类型转换和2种隐式类型转换? 强制(parse ...
- mac下Apache + MySql + PHP网站开发
最近接了个小活,做一个使用PHP语言和MySql数据库的动态网站.之前做过类型的网站,是在windows系统下做的,开发环境使用的是 AppServ 的PHP开发套件.现在有了我的大MAC,所以找了M ...