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 ...
随机推荐
- iOS开发之常用第三方框架(下载地址,使用方法,总结)
iOS开发之常用第三方框架(下载地址,使用方法,总结) 说句实话,自学了这么久iOS,如果说我不知道的但是又基本上都摸遍了iOS相关知识,但是每次做项目的时候,遇到难一点的地方或者没试过的东西就闷了. ...
- Qt中文乱码问题(比较清楚,同一个二进制串被解释成不同的语言)
文章来源:http://blog.csdn.net/brave_heart_lxl/article/details/7186631 以下是dbzhang关于qt中文乱码问题原因的阐述,觉得不错: 首先 ...
- 关于API的设计和需求抽象
一,先来谈抽象吧,因为抽象跟后面的API的设计是息息相关的 有句话说的好(不知道谁说的了):计算机科学中的任何问题都可以抽象出一个中间层就解决了. 抽象是指在思维中对同类事物去除其现象的.次要的方面, ...
- NOI2015
D1T1 并查集. #include<cstdio> #include<cstdlib> #include<iostream> #include<fstrea ...
- java内存模型和线程
概述 多任务的处理在现在的计算机中可以说是"标配"了,在许多的情况下,让计算机同时做几件事情,不仅是因为计算机的运算能力的强大,还有一个重要的原因是:cpu的运算速度和计算机的存储 ...
- leetcode:Multiply Strings(字符串的乘法)【面试算法题】
题目: Given two numbers represented as strings, return multiplication of the numbers as a string. Note ...
- javascript自定义浏览器右键菜单
javascript自定义浏览器右键菜单 在书上看到document对象还有一个contextmenu事件,但是不知为什么w3school中找不到这个耶... 利用这个特性写了个浏览器的右键菜单, ...
- servlet下载,解决文件名中有中文下载路径出现乱码不能正常下载问题
方法很多种,我只试用了两种. 主页面JSP中引入下载功能所需的js文件.引入的时候设置编码格式例如 <script type="text/javascript" charse ...
- C/C++变量命名规则
变量命名规则是为了增强代码的可读性和easy维护性. 变量命名规则: 一.用最短字符表示最准确的意义. 二.使用变量前缀. 1. 整型前缀 int nId; ...
- JMeter录制脚本
Jmeter 是一个非常流行的性能测试工具,虽然与LoadRunner相比有很多不足,比如:它结果分析能力没有LoadRunner详细:很它的优点也有很多: l 开源,他是一款开源的免费软件,使用它你 ...