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 ...
随机推荐
- cf C. Valera and Elections
http://codeforces.com/contest/369/problem/C 先见边,然后dfs,在回溯的过程中,如果在这个点之后有多条有问题的边,就不选这个点,如果没有而且连接这个点的边还 ...
- jsonp+handler 的实现
//参考 http://www.cnblogs.com/yuwensong/archive/2013/05/28/3103064.html 后台: public void ProcessRequest ...
- MyBatis 通过包含的jdbcType类型和java中对应的数据类型
MyBatis 通过包含的jdbcType类型 BIT FLOAT CHAR TIMESTAMP OTHER UNDEFINED ...
- [原创作品] RequireJs入门进阶教程
最近我发现RSS采集数据是个很好玩的东西,就是可以直接把别人的数据放在自己的网站上.如果网友们在其他地方发现这篇文章,还是来博客园看吧(http://zhutty.cnblogs.com).这样代码比 ...
- hdu4055 dp
http://acm.hdu.edu.cn/showproblem.php?pid=4055 Problem Description The signature of a permutation is ...
- javascript正則表達式 "\b"问题
preface 昨晚在看<javascript权威指南>后.看见作者自己封装一个兼容全部浏览器的山寨HTML5新API classLIst类.自己想了想认为自己也要去玩一下.可是能力还是有 ...
- hdu 3056 病毒侵袭持续中 AC自己主动机
http://acm.hdu.edu.cn/showproblem.php?pid=3065 刘汝佳的模板真的非常好用,这道题直接过 学到: cnt数组记录单词出现次数 以及map存储单词编号与字符串 ...
- DB2查询当前时间与指定时间的时间差(相隔的秒数)
DB2查询当前时间与指定时间的时间差(相隔的秒数). 例子:“拍品表 auct_item”中有个“结束时间 end_date”的字段,求结束时间与当前时间的间隔秒数. select (DAYS(a. ...
- windows下删除服务的方法
删除的办法有两个: 办法一: 用sc.exe这个Windows命令 开始——运行——cmd.exe,然后输入sc就可以看到了.使用办法很简单: sc delete "服务名" (如 ...
- shell常用命令的用法
1. 如何把 /etc/passwd 中用户uid 大于500 的行给打印出来?awk -F ':' '$3>500' /etc/passwd 2. awk中 NR,NF两个变量表示什么含义?N ...