HDU 5952 [DFS]
题目链接:【http://acm.hdu.edu.cn/showproblem.php?pid=5952】
题意:给出一张无向图,然后判断这张图中一共有多少个不同的大小为S的完全图,并且保证每个点的度不大于20。
题解:好吧,比赛的时候想太多了,结果时间刚不住,TTTT。正解其实很简单,就一个DFS。每次建立DFS(u),表示u在的大小为S的完全图个数,为了保证不重复,我们只建立单向边。每层DFS的时候,取一个点,当且仅的这个点与之前的所有点选过的点有边相连(神优化)。总复杂度是100 * 100 * (2 ^ 19) ,但是,应为边很少,所以,复杂度要少很多。
思维僵化啊。
#include<Bits/stdc++.h>
using namespace std;
const int maxn = 105;
int T, N, M, S;
struct Edge
{
int to, next;
Edge() {}
Edge(int to, int next): to(to), next(next) {}
} E[2050];
int head[maxn], tot;
int mp[maxn][maxn], vis[maxn], tmp[maxn];
int ans = 0;
void initEdge()
{
for(int i = 0; i <= N; i++) head[i] = -1;
tot = 0;
}
void addEdge(int u, int v)
{
E[tot] = Edge(v, head[u]);
head[u] = tot++;
}
void DFS(int u, int pos)
{
if(pos == S)
{
ans++;
return ;
}
for(int k = head[u]; ~k; k = E[k].next)
{
int v = E[k].to;
bool fg = true;
for(int i = 0; i < pos && fg; i++)
if(!mp[v][tmp[i]]) fg = false;
if(fg)
{
tmp[pos] = v;
DFS(v, pos + 1);
}
}
return ;
}
int main ()
{
scanf("%d", &T);
while(T--)
{
scanf("%d %d %d", &N, &M, &S);
initEdge();
for(int i = 1; i <= N; i++)
{
vis[i] = 0;
for(int j = i + 1; j <= N; j++)
mp[i][j] = mp[j][i] = 0;
}
for(int i = 1; i <= M; i++)
{
int u, v;
scanf("%d %d", &u, &v);
addEdge(u, v);
mp[u][v] = mp[v][u] = 1;
}
if(S == 2)
{
printf("%d\n", M);
continue;
}
ans = 0;
for(int i = 1; i <= N; i++)
{
tmp[0] = i;
DFS(i, 1);
} printf("%d\n", ans);
}
return 0;
}
HDU 5952 [DFS]的更多相关文章
- HDU - 5952 Counting Cliques
Counting Cliques HDU - 5952 OJ-ID: hdu-5952 author:Caution_X date of submission:20191110 tags:dfs,gr ...
- HDU 5143 DFS
分别给出1,2,3,4 a, b, c,d个 问能否组成数个长度不小于3的等差数列. 首先数量存在大于3的可以直接拿掉,那么可以先判是否都是0或大于3的 然后直接DFS就行了,但是还是要注意先判合 ...
- Snacks HDU 5692 dfs序列+线段树
Snacks HDU 5692 dfs序列+线段树 题意 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充, ...
- HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)
Counting Cliques Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- Counting Cliques HDU - 5952 单向边dfs
题目:题目链接 思路:这道题vj上Time limit:4000 ms,HDU上Time Limit: 8000/4000 MS (Java/Others),且不考虑oj测评机比现场赛慢很多,但10月 ...
- HDU - 5952 Counting Cliques(DFS)
A clique is a complete graph, in which there is an edge between every pair of the vertices. Given a ...
- HDU - 5952 Counting Cliques(dfs搜索)
题目: A clique is a complete graph, in which there is an edge between every pair of the vertices. Give ...
- HDU 5952 Counting Cliques(dfs)
Counting Cliques Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 5877 dfs+ 线段树(或+树状树组)
1.HDU 5877 Weak Pair 2.总结:有多种做法,这里写了dfs+线段树(或+树状树组),还可用主席树或平衡树,但还不会这两个 3.思路:利用dfs遍历子节点,同时对于每个子节点au, ...
随机推荐
- Shell编程——vim常用命令
[vim]工作模式切换: 在普通模式下输入 i(插入).c(修改).o(另起一行) 命令时进入编辑模式:按 esc 键退回到普通模式. 在普通模式下输入冒号(:)可以进入命令模式.输入完命 ...
- amcharts的一些用法
function chartdiv2() { var chart; var chartData = [ { "month" : "2015-08", " ...
- vue-router.esm.js?fe87:16 [vue-router] Route with name 'page' does not exist
本文地址:http://www.cnblogs.com/veinyin/p/7910525.html 我的路由配置 { path: '/page', name: page, component: pa ...
- VC字体对话框的初始化
本代码需要先添加类成员 LOGFONT lf; void CMyDlg::OnButton3() { // TODO: Add your control notification handler c ...
- 【appium】根据UIAutomator定位元素等等资料
https://www.cnblogs.com/paulwinflo/p/4742529.html http://www.cnblogs.com/meitian/p/6103391.html http ...
- NuGet Package Explorer上传时报:failed to process request:'Method Not Allowed'错误解决办法
相关日志:PUT /api/v2/package - 1000 - NuGet+Package+Explorer/3.15.0.0+(Microsoft+Windows+NT+6.2.9200.0) ...
- cmder中文显示相关问题解决方案(1.3以上版本)
cmder虽然Windows命令行的进阶版,虽然好看易用,但其中文编码一直是个问题.网上有不少博客给出解决方案,大部分都已因为版本更新失效.本文解决方案针对1.3以上版本的cmder用户 中文字体重叠 ...
- Jmeter命令行选项
示例:jmeter.bat -n -j %tmp%\%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%%time:~ ...
- Django自定义UserModel并实现认证和登录
自定义UserModel 环境:django 1.9.11+python 2.7 from django.contrib.auth.models import AbstractUser class U ...
- JavaScript 去字符串空格
JavaScript 去字符串空格 (利用正则) # str为要去除空格的字符串: # 去除所有空格: str = str.replace(/\s+/g,""); # 去除两头空格 ...