hdu 5305Friends
For each testcase, the first line contains two integers n (1≤n≤8) and m (0≤m≤n(n−1)2), indicating the number of people and the number of pairs of friends, respectively. Each of the next m lines contains two numbers x and y, which mean x and y are friends. It is guaranteed that x≠y and every friend relationship will appear at most once.
3 3
1 2
2 3
3 1
4 4
1 2
2 3
3 4
4 1
数据比较小,直接暴力深搜即可。
#include <iostream>
#include <cstring>
using namespace std; struct w
{
int x;
int y;
}p[];
int a[],b[],n,m,num[],ans;
void dfs(int k)
{
if (k==m+)
{
ans++;
return ;
}
if (a[p[k].x]&&a[p[k].y])
{
a[p[k].x]--;
a[p[k].y]--;
dfs(k+);
a[p[k].x]++;
a[p[k].y]++;
}
if (b[p[k].x]&&b[p[k].y])
{
b[p[k].x]--;
b[p[k].y]--;
dfs(k+);
b[p[k].x]++;
b[p[k].y]++;
}
return ;
} int main()
{
int t;
cin>>t;
while (t--)
{
cin>>n>>m;
ans=;
memset(a,,sizeof(a));
memset(b,,sizeof(b));
memset(num,,sizeof(num));
for (int i=;i<=m;i++)
{
cin>>p[i].x>>p[i].y;
num[p[i].x]++;
num[p[i].y]++;
}
int flag=;
for (int i=;i<=n;i++)
{
a[i]=b[i]=num[i]/;
if (num[i]%!=)//朋友总数是奇数的肯定不符合在线和不在线的人数相等
{
flag=;
//break;
}
}
if (!flag)
{
cout <<<<endl;
continue;
}
dfs();
cout <<ans<<endl;
}
return ;
}
hdu 5305Friends的更多相关文章
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
- hdu 4329
problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟 a. p(r)= R'/i rel(r)=(1||0) R ...
随机推荐
- UC/OS操作系统 (转)
1.和其他一些著名的嵌入式操作系统不同,uC/OS-II在单片机系统中的启动过程比较简单,不像有些操作系统那样,需要把内核编译成一个映像文件写入ROM中,上电复位后,再从ROM中把文件加载到RAM中去 ...
- Qt自定义sleep延时函数(巧妙的使用时间差,但这样似乎CPU满格,而不是沉睡)
Qt不像VC++的win32/MFC编程那样,提供了现成的sleep函数可供调用.Qt把sleep函数封装在QThread类中.子线程可以调用sleep函数.但是如果用户想在主线程实现延时功能,该怎么 ...
- Java Thread Status(转)
public static enum Thread.State extends Enum<Thread.State>线程状态.线程可以处于下列状态之一: 1.NEW 至今尚未启动的线程的 ...
- centos下httpd 启动失败的解决办法
[root@csit yang]# service httpd start Starting httpd: [FA ...
- SOSP 文档 - Windows Azure 存储:具有强一致性的高可用性云存储服务
之前,我们在第 23 届 ACM操作系统原理研讨会 (SOSP)上发布了一篇文章,其中介绍了 Windows Azure存储的内部详细信息. 您可以在此处找到该文章.此次大会还发布了一段视频讲话( ...
- linux内核--中断和中断处理(一)
让硬件在需要的时候再向内核发出信号.这就是中断机制,先讨论中断,进而讨论内核如何使用所谓的中断处理函数处理对应的中断. 一.中断 1)中断 中断使得硬件得以发出通知给处理器.例如, ...
- centerOS安装rkhunter
rkhunter是专业检测系统是否感染rootkit的一个工具: rkhunter-1.4.2.tar.gz 解压后直接安装: #./installer.sh --layout defualt --i ...
- c3p0数据源定义
<!-- c3p0 connection pool configuration --> <bean id="testDataSource" class=" ...
- js高级程序设计(第三版)学习笔记(第一版)
ecma:欧洲计算机制造商协会iso/iec:国际标准化和国际电工委员会 dom级别(10*)文档对象模型1:DOM核心(映射基于xml文档)与dom html(在dom核心基础上)2:对鼠标,事件, ...
- Python 中文报错 SyntaxError: Non-ASCII character解决办法
只需要在最顶部的位置加上 #-*- coding:utf-8 -*- 就行了. 如果还是没有好,打开设置并搜索file encoding并作如图修改便好.