题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5305
Problem Description
There are n people and m pairs of friends. For every pair of friends, they can choose to become online friends (communicating using online applications) or offline friends (mostly using face-to-face communication). However, everyone in these n people wants to have the same number of online and offline friends (i.e. If one person has x onine friends, he or she must have x offline friends too, but different people can have different number of online or offline friends). Please determine how many ways there are to satisfy their requirements. 
 
Input
The first line of the input is a single integer T (T=100), indicating the number of testcases.

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. 

 
Output
For each testcase, print one number indicating the answer.
 
Sample Input
2
3 3
1 2
2 3
3 1
4 4
1 2
2 3
3 4
4 1
 
Sample Output
0 2

数据比较小,直接暴力深搜即可。

 #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的更多相关文章

  1. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  3. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  4. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  5. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  6. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  7. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  8. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

  9. hdu 4329

    problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟  a.     p(r)=   R'/i   rel(r)=(1||0)  R ...

随机推荐

  1. CoreGraphics 之CGAffineTransform仿射变换(3)

    CoreGraphics 之CGAffineTransform仿射变换(3)   CoreGraphics 的 仿射变换 可以用于 平移.旋转.缩放变换路径 或者图形上下文. (1)平移变换将路径或图 ...

  2. angularJs项目实战!01:模块划分和目录组织

    近日来我有幸主导了一个典型的web app开发.该项目从产品层次来说是个典型的CRUD应用,故而我毫不犹豫地采用了grunt + boilerplate + angularjs + bootstrap ...

  3. Commons Beanutils使用setProperty() - 就是爱Java

    有时不能只依靠getter/setter操作bean,如:需要名字动态取得的,或是访问bean内的field,甚至是集合或数组内bean的field,利用反射机制对bean的field进行处理,这时候 ...

  4. android-support-v7-appcompat的配置使用

    直接将android-support-v7-appcompat.jar包拷贝到项目的libs/下面是不能使用的,具体做法官方文档给出了详细说明: (开发环境是ADT) Using Eclipse Cr ...

  5. leetcode_Substring with Concatenation of All Words

    You are given a string, S, and a list of words, L, that are all of the same length. Find all startin ...

  6. centos下httpd 启动失败的解决办法

    [root@csit yang]# service httpd start Starting httpd:                                            [FA ...

  7. 【转】Win7、Ubuntu双系统正确卸载Ubuntu系统--不错

    原文网址:http://my.oschina.net/u/1377657/blog/281872 如果ubuntu不是以wubi方式安装的,而是U盘或者光盘装的双系统,那么卸载ubuntu时要慎重,不 ...

  8. JS实现 鼠标放上去 图片自动放大的效果

    前段时间做项目,要实现,一张图片,鼠标放上去图片自动变大的效果,虽然难度不大,但当时也想了一段时间,当时没时间记录一下,现在有时间了,写篇博客把代码给记录一下: 效果如下: 代码如下: <!DO ...

  9. NET分布式缓存Memcached测试体验

    原文地址:http://onlyonewt.blog.sohu.com/160168896.html 一直在学习关注大访问量网站的缓存是如何实现,之前看过Memcached的资料,忙于没有时间来真正测 ...

  10. hdu1573:数论,线性同余方程组

    题目大意: 给定一个N ,m 找到小于N的  对于i=1....m,满足  x mod ai=bi  的 x 的数量. 分析 先求出 同余方程组 的最小解x0,然后 每增加lcm(a1...,am)都 ...