题目链接:传送门

题目:

Counting Cliques
Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others)
Total Submission(s): Accepted Submission(s): Problem Description
A 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. Input
The first line is the number of test cases. For each test case, the first line contains integers N,M and S (N ≤ ,M ≤ , ≤ S ≤ ), each of the following M lines contains integers u and v ( ≤ 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 . Output
For each test case, output the number of cliques with size S in the graph. Sample Input Sample Output

题目大意:

  给定一个有N个点,M条边的图,求有S个点的完全子图的数量。

  (N ≤ 100,M ≤ 1000,2 ≤ S ≤ 10)

思路:

  一个个点加入完全子图,大小达到S时ans++。

  纯暴力好像会在4000ms上下徘徊,随便剪一下就过了。

代码:

#include <bits/stdc++.h>

using namespace std;
const int MAX_N = 1e2 + ;
const int MAX_M = 1e3 + ; int N, M, S;
int ans;
bool edge[MAX_N][MAX_N];
vector <int> Edge[MAX_N];
int vis[MAX_N]; int read() {
int res = ;
char ch = getchar();
while (!isdigit(ch)) ch = getchar();
while (isdigit(ch)) {
res *= ;
res += ch - '';
ch = getchar();
}
return res;
} void dfs(int dep, int u)
{
if (Edge[u].size() < S-)
return;
if (S-dep + u > N)
return;
if (dep == S) {
ans++;
return;
} int Elen = Edge[u].size();
for (int i = ; i < Elen; i++) {
int v = Edge[u][i];
if (v < u)
continue;
if (Edge[v].size() < dep)
continue;
bool ok = true;
for (int j = ; j <= dep; j++){
int w = vis[j];
if (!edge[v][w]) {
ok = false;
break;
}
} if (ok) {
vis[dep+] = v;
dfs(dep+, v);
}
}
} void addEdge(int u, int v) {
edge[u][v] = edge[v][u] = true;
Edge[u].push_back(v);
Edge[v].push_back(u);
} int main()
{
int T;
cin >> T;
while (T--) {
N = read();
M = read();
S = read();
for (int i = ; i <= N; i++) {
Edge[i].clear();
for (int j = ; j <= N; j++)
edge[i][j] = false;
}
int u, v;
for (int i = ; i <= M; i++) {
u = read();
v = read();
addEdge(u, v);
}
ans = ;
for (int i = ; i <= N; i++) {
vis[] = i;
dfs(, i);
}
printf("%d\n", ans);
}
return ;
}

HDU5952 Counting Cliques (暴力深搜+剪枝) (2016ACM/ICPC亚洲赛区沈阳站 Problem E)的更多相关文章

  1. HDU5950 Recursive sequence (矩阵快速幂加速递推) (2016ACM/ICPC亚洲赛区沈阳站 Problem C)

    题目链接:传送门 题目: Recursive sequence Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total ...

  2. Hdu3812-Sea Sky(深搜+剪枝)

    Sea and Sky are the most favorite things of iSea, even when he was a small child.  Suzi once wrote: ...

  3. poj1190 生日蛋糕(深搜+剪枝)

    题目链接:poj1190 生日蛋糕 解题思路: 深搜,枚举:每一层可能的高度和半径 确定搜索范围:底层蛋糕的最大可能半径和最大可能高度 搜索顺序:从底层往上搭蛋糕,在同一层尝试时,半径和高度都是从大到 ...

  4. UVA 10160 Servicing Stations(深搜 + 剪枝)

    Problem D: Servicing stations A company offers personal computers for sale in N towns (3 <= N < ...

  5. ACM 海贼王之伟大航路(深搜剪枝)

    "我是要成为海贼王的男人!" 路飞他们伟大航路行程的起点是罗格镇,终点是拉夫德鲁(那里藏匿着"唯一的大秘宝"--ONE PIECE).而航程中间,则是各式各样的 ...

  6. hdu 1518 Square(深搜+剪枝)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1518 题目大意:根据题目所给的几条边,来判断是否能构成正方形,一个很好的深搜应用,注意剪枝,以防超时! ...

  7. POJ-1724 深搜剪枝

    这道题目如果数据很小的话.我们通过这个dfs就可以完成深搜: void dfs(int s) { if (s==N) { minLen=min(minLen,totalLen); return ; } ...

  8. 一本通例题-生日蛋糕——题解<超强深搜剪枝,从无限到有限>

    题目传送 显然是道深搜题.由于蛋糕上表面在最底层的半径确认后就确认了,所以搜索时的面积着重看侧面积. 找维度/搜索面临状态/对象:当前体积v,当前外表面面积s,各层的半径r[],各层的高度h[]. 可 ...

  9. 模拟赛T5 : domino ——深搜+剪枝+位运算优化

    这道题涉及的知识点有点多... 所以还是比较有意思的. domino 描述 迈克生日那天收到一张 N*N 的表格(1 ≤ N ≤ 2000),每个格子里有一个非 负整数(整数范围 0~1000),迈克 ...

随机推荐

  1. Oracle中如何停止正在执行SQL语句

    oracle的用P/SQL客户端中,如何停止正在执行的SQL语句? 我们使用oracle语句查询某个表时,如果查询的表数据太多,如何停止正在执行操作 如查询的表数据超过上万条时,如何停止查询操作

  2. Easyui的datagrid的editor(行编辑器)如何扩展datetimebox类型

    在easyui的datagrid扩展方法中添加这样的时间日期(datetimebox)代码块 放在   $.extend($.fn.datagrid.defaults.editors,{datetim ...

  3. mac nginx+php-fpm配置(安装过后nginx后访问php文件下载,访问php文件请求200显示空白页面)

    访问php文件下载是因为没配置php-fpm 两个问题主要都是nginx.conf配置的问题: /usr/local/etc/nginx/nginx.conf server {    listen 8 ...

  4. Oracle.数据的增删改、表操作(创建,修改,删除)、数据类型

    SELECT ename,dname FROM emp,dept WHERE emp.deptno=dept.deptno; SELECT dname,loc FROM dept; SELECT JO ...

  5. java串口编程

    报错:no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDrive java.lang.Unsatisfie ...

  6. 笨办法11提问-raw_input

    源代码如下,有个改动 print "How old are you?", age = raw_input() print "How tall are you?" ...

  7. json 2017-04-21 10 17

    jo := SO(); jo.S['tttt'] := 'tttt'; TbSendedTidJson['jo'] := jo; ja := TbSendedTidJson['jo'];//取出来后, ...

  8. 十七. Python基础(17)--正则表达式

    十七. Python基础(17)--正则表达式 1 ● 正则表达式 定义: Regular expressions are sets of symbols that you can use to cr ...

  9. MyEclipse使用教程:在Web项目中使用Web片段

    MyEclipse 在线订购年终抄底促销!火爆开抢>> MyEclipse最新版下载 本教程向用户展示了使用关联的Web项目创建Web片段项目的机制.用户还可以获得要检查的示例项目.在本教 ...

  10. 20165326 java第三周学习笔记

    纸质学习笔记 代码托管