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 ...
随机推荐
- 程序设计C 实验三 题目九 方程式(0300)
Description: Consider equations having the following form: a*x1*x1 + b*x2*x2 + c*x3*x3 + d*x4*x4 = 0 ...
- IOS 客户端测试入门.pdf
IOS 客户端测试入门 http://www.open-open.com/doc/view/42d1257bf67946f595e843bfdbdfeabf
- [HDU] 1068 Girls and Boys(二分图最大匹配)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1068 本题求二分图最大独立点集.因为最大独立点集=顶点数-最大匹配数.所以转化为求最大匹配.因为没有给 ...
- cf Strings of Power
http://codeforces.com/contest/318/problem/B #include <cstdio> #include <cstring> #includ ...
- 工控主板EM9161对ISO7816协议的支持
在当前的金融POS终端及相关领域,ISO7816通讯协议得到了广泛应用.英创的工控主板EM9161,可在其异步串口的基础上,通过简单的设置,就可把串口转为符合ISO7816协议的接口,实现与各种智能卡 ...
- qmake使用实践:包含动态库的Qt4工程
文章来源:http://blog.csdn.net/dbzhang800/article/details/6317006 本文是qmake的一个使用练习,是半年前所学的 分析与学习Qt Solutio ...
- C#中使用SendMessage进行进程通信的实例
原文:C#中使用SendMessage进行进程通信的实例 1 新建解决方案SendMessageSecondExample 在解决方案下面新建两个项目:Sender和Receiver,两者的输出类型均 ...
- 关于bootstrap--列表(ol、ul)
1.list-unstyled : 在<ol>(有序列表)</ol><ul>(无序列表)</ul>中加入class="list-styled& ...
- <php>PDO链接方法
<?php //定义数据源 $dsn = "mysql:dbname=mydb;host=localhost"; //$dsn = "sqlsrv:dbname=m ...
- <php>删除(有内容的)文件夹函数程序
function deldir($dirname) { if(!file_exists($dirname)) {//判断文件夹是否存在 die("文件夹不存在!");//作用等于( ...