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),迈克 ...
随机推荐
- git rebase commit 信息处理
pick:正常选中 reword:选中,并且修改提交信息: edit:选中,rebase时会暂停,允许你修改这个commit(参考这里) squash:选中,会将当前commit与上一个commit合 ...
- windows7时间同步设置
1. 设置同步源 服务器修改为本车的104的ip地址,例如23车,手动输入 96.3.123.104 2. 设置同步周期. 注册表法 在“运行”框输入“Regedit”进入注册表编辑器 这种方法是通过 ...
- Java字符串拼接效率测试
测试代码: public class StringJoinTest { public static void main(String[] args) { int count = 10000; long ...
- 【阅读笔记】《C程序员 从校园到职场》第二章 学校到职场
一.代码规范: 1.变量命名(让人一眼看它是什么意思,要做什么操作),定义并初始化 2.函数命名规范(函数的功能)在主函数之前进行声明. 在实际项目中,一般不在函数调用者的内部来对被调函数进行声明,而 ...
- let var区别
function varTest() { var x = 1; if (true) { var x = 2; // 同样的变量! console.log(x); } console.log(x); } ...
- 阶段01Java基础day10面向对象05
10.01_面向对象(package关键字的概述及作用) A:为什么要有包 将字节码(.class)进行分类存放 B:包的概述 C:包的作用 10.02_面向对象(包的定义及注意事项) A:定义包的格 ...
- mySql单列索引与联合索引的区别
引自https://my.oschina.net/857359351/blog/658668 第一张表gift和索引为联合索引,如图: 第二张表gift2为单列索引,如图: 下面开始进行测试: 相同的 ...
- UBUNTU 测试跑分
time echo "scale=5000; 4*a(1)" | bc -l -q3.14159265358979323846264338327950288419716939937 ...
- 基于Nutch Solr等基于搭建一体化的数据抓取平台
参考链接:https://www.ibm.com/developerworks/cn/opensource/os-cn-BigInsightsNutchSolr/
- 福大软工 · BETA 版冲刺前准备之拖鞋旅游队
拖鞋旅游队BETA 版冲刺前准备 前言 队名:拖鞋旅游队 组长博客:https://www.cnblogs.com/Sulumer/p/10083834.html 本次作业:https://edu.c ...