HDU5952 Counting Cliques (暴力深搜+剪枝) (2016ACM/ICPC亚洲赛区沈阳站 Problem E)
题目链接:传送门
题目:
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)的更多相关文章
- HDU5950 Recursive sequence (矩阵快速幂加速递推) (2016ACM/ICPC亚洲赛区沈阳站 Problem C)
题目链接:传送门 题目: Recursive sequence Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total ...
- Hdu3812-Sea Sky(深搜+剪枝)
Sea and Sky are the most favorite things of iSea, even when he was a small child. Suzi once wrote: ...
- poj1190 生日蛋糕(深搜+剪枝)
题目链接:poj1190 生日蛋糕 解题思路: 深搜,枚举:每一层可能的高度和半径 确定搜索范围:底层蛋糕的最大可能半径和最大可能高度 搜索顺序:从底层往上搭蛋糕,在同一层尝试时,半径和高度都是从大到 ...
- UVA 10160 Servicing Stations(深搜 + 剪枝)
Problem D: Servicing stations A company offers personal computers for sale in N towns (3 <= N < ...
- ACM 海贼王之伟大航路(深搜剪枝)
"我是要成为海贼王的男人!" 路飞他们伟大航路行程的起点是罗格镇,终点是拉夫德鲁(那里藏匿着"唯一的大秘宝"--ONE PIECE).而航程中间,则是各式各样的 ...
- hdu 1518 Square(深搜+剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1518 题目大意:根据题目所给的几条边,来判断是否能构成正方形,一个很好的深搜应用,注意剪枝,以防超时! ...
- POJ-1724 深搜剪枝
这道题目如果数据很小的话.我们通过这个dfs就可以完成深搜: void dfs(int s) { if (s==N) { minLen=min(minLen,totalLen); return ; } ...
- 一本通例题-生日蛋糕——题解<超强深搜剪枝,从无限到有限>
题目传送 显然是道深搜题.由于蛋糕上表面在最底层的半径确认后就确认了,所以搜索时的面积着重看侧面积. 找维度/搜索面临状态/对象:当前体积v,当前外表面面积s,各层的半径r[],各层的高度h[]. 可 ...
- 模拟赛T5 : domino ——深搜+剪枝+位运算优化
这道题涉及的知识点有点多... 所以还是比较有意思的. domino 描述 迈克生日那天收到一张 N*N 的表格(1 ≤ N ≤ 2000),每个格子里有一个非 负整数(整数范围 0~1000),迈克 ...
随机推荐
- 用Python读取文件
1. 读取TXT文件 CODE CUR PRV. CLOSING RATE HIGH LOW CLOSING SHARES TRADED TURNOVER ($) 代號 NAME OF STOCK 股 ...
- learning ddr mode register MR0
- img2html实现将图片转换成网页
简单介绍img2html的用法,安装就不用说了pip.这个包现只支持python2,支持python的话需改下源码这几个部分: 加注释的是修改的地方 #!/usr/bin/env python # e ...
- django_rq无法监听两个队列问题
django_rq是为django集成redis队列,这个用的少,一般会选择celery,没办法项目中用到了.用起来很简单,配置可以参考官方文档:https://pypi.org/project/dj ...
- Windows Server 2016与旧版本系统比较
一.性能和可扩性 特征描述 Windows Server 2012/2012 R2 标准版和数据中心 Windows Server 2016 标准版和数据中心 物理内存(主机)支持 每个物理服务器至多 ...
- jenkins部署java项目到远程linux(四)
(1)新建java项目(maven构建) pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:x ...
- day056 多表增加和查询
今日总结: 多表的增删改查操作 多表操作 增 book id title book_detail publish author onetoone manytoone manytomany book_o ...
- elasticsearch基本操作之--使用QueryBuilders进行查询
/** * 系统环境: vm12 下的centos 7.2 * 当前安装版本: elasticsearch-2.4.0.tar.gz */ QueryBuilder 是es中提供的一个查询接口, 可以 ...
- 7.3 C++模板中的函数式参数
参考:http://www.weixueyuan.net/view/6400.html 总结: 模板类至少有一个类参数,但是可以有多个参数,这些参数中可以存在非类类型的参数. 类参数是指 class ...
- 一次练习 发现的问题,malloc free 无效;findfirstfile失败,writefile失败的原因
#include <windows.h> #include <stdio.h> #include <shlwapi.h> #pragma comment(lib,& ...