题目链接:传送门

题目:

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. python删除指定路径的文件

    import os            import glob                        path =imgDate_listResult            for infi ...

  2. 码云git使用一(上传本地项目到码云git服务器上)

    主要讲下如果将项目部署到码云git服务器上,然后使用studio导入git项目,修改本地代码后,并同步到码云git上面. 首先:我们在码云上注册账号并登陆.官网(https://git.oschina ...

  3. IIS发布网站,访问时出现无法识别的属性“targetFramework”错误

    今天在IIS发布网站后,访问时出现无识别的属性“targetFramework”错误 错误描述: 错误原因: 是由IIS配置该站点的.NET Framework 版本与程序中的.NET Framewo ...

  4. C#中使用SqlBulkCopy的批量插入和OracleBulkCopy的批量插入

    1.首先我们做一下准备工作,在sql server和oracle分别建立一个Student表 oracle中 --创建Student表 -- create table Student( stuId n ...

  5. Guidelines for Writing a Good NIPS Paper

    By the NIPS 2006 Program Committee With input from Andrew Ng, Peter Dayan, Daphne Koller, Sebastian ...

  6. C# [IPA]IOS In App Purchase(内购)验证(asp.net 版本)

    之前没有做过IOS 内购服务器验证这块,所以找了不少参考资料,网上大多php和java版本,然后自己搞了一个C#版本,希望能给大家一些参考,下面步入正题 在客户端向苹果购买成功之后,我们需要进行二次验 ...

  7. .net core Asp.net Mvc Ef 网站搭建 vs2017 1)

    1)开发环境搭建 首先下载安装vs2017  地址 :https://www.visualstudio.com/zh-hans/downloads/ 安装勾选几项如下图 ,注意点在单个组件时.net ...

  8. tomcat 服务器线程问题

    http://blog.csdn.net/wtopps/article/details/71339295 http://blog.csdn.net/wtopps/article/details/713 ...

  9. C语言转义字符'\'

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  10. Spring MVC中注解: @ModelAttribute 与@RequestParam区别

    相关链接 : https://blog.csdn.net/huang343/article/details/77491096