Friends

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1192    Accepted Submission(s): 595

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
 
Source
 
Recommend
wange2014   |   We have carefully selected several similar problems for you:  5309 5308 5307 5306 5304 
题目描述:
将图中的每个点相连的边分配成两种边,求有多少种分配方式.
每条边有两种状态的选择,怎么样枚举边的选择是个问题,采用两个数组c1[]和c2[]分别记录每个点这两种边的数量,初始数量相等,
选0状态,c1[i]数组--,选1状态,c2[i]数组--,这样就可以枚举边的选择.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
#define maxn 30
int n,m;
int ans;
int c1[maxn],c2[maxn];
int deg[maxn];
struct Edge
{
int from,to;
}edges[]; void init()
{
ans=;
memset(c1,,sizeof(c1));
memset(c2,,sizeof(c2));
memset(deg,,sizeof(deg));
} void dfs(int e)
{
if(e==m+) //能够搜到第m+1次,说明每条边都分配了0或者1,减了2*m次,c1和c2数组都为0
{
ans++;
return ;
}
int from=edges[e].from,to=edges[e].to;
if(c1[from] && c1[to]) //这条边分配0
{
c1[from]--; c1[to]--;
dfs(e+);
c1[from]++; c1[to]++;
}
if(c2[from] && c2[to]) //这条边分配1
{
c2[from]--; c2[to]--;
dfs(e+);
c2[from]++; c2[to]++;
}
return ; //如果这条边既不能分配0,也不能分配1,只能回溯
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
init();
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
{
scanf("%d%d",&edges[i].from,&edges[i].to);
deg[edges[i].from]++;
deg[edges[i].to]++;
}
// for(int i=1;i<=n;i++)
// printf("%d ",deg[i]);
// cout<<endl;
int flag=;
for(int i=;i<=m;i++)
{
int from=edges[i].from,to=edges[i].to;
if( (deg[from] & ))
{
flag=; break;
}
if( (deg[to] & ))
{
flag=; break;
}
c1[from]= (deg[from] >> ); //from的在线朋友数量
c2[from]= (deg[from] >> ); //from的在线朋友数量
//from这个点的在线朋友和离线朋友都为它度数的一半
c1[to] = (deg[to] >> ); //to的离线朋友数量
c2[to]= (deg[to] >> ); //to的离线朋友数量
}
if(flag==)
{
printf("0\n");
continue;
}
dfs();
printf("%d\n",ans);
}
return ;
}

hdu 3503(有点小技巧的dfs(对结点加东西表示边的某些状态))的更多相关文章

  1. visual studio 一些小技巧 整理

    本博客将会陆续的整理一些作者在实际开发中的一些小技巧,一些挺有意思的东西,将会持续更新, 如果有问题,可以加群讨论,QQ群:592132877 #warning的使用 #warning 的意思是在程序 ...

  2. HDU 5895 Mathematician QSC(矩阵乘法+循环节降幂+除法取模小技巧+快速幂)

    传送门:HDU 5895 Mathematician QSC 这是一篇很好的题解,我想讲的他基本都讲了http://blog.csdn.net/queuelovestack/article/detai ...

  3. HDU -2674 N!Again(小技巧)

    这道题有个小技巧,就是既然是n!,那么对2009求余,只要大于2009!,那么一定是0,在仔细想想会发现,根本到不了2009,只要到2009的最大质因数就行了,为什么呢?因为最大质因数是最大的一个不能 ...

  4. Git小技巧 - 指令别名及使用Beyond Compare作为差异比较工具

    前言 本文主要写给使用命令行来操作Git的用户,用于提高Git使用的效率.至于使用命令还是GUI(Tortoise Git或VS的Git插件)就不在此讨论了,大家根据自己的的喜好选择就好.我个人是比较 ...

  5. HDU 1078 FatMouse and Cheese ( DP, DFS)

    HDU 1078 FatMouse and Cheese ( DP, DFS) 题目大意 给定一个 n * n 的矩阵, 矩阵的每个格子里都有一个值. 每次水平或垂直可以走 [1, k] 步, 从 ( ...

  6. 小技巧(updating)

    小技巧 我们要算一个点集中所有点到另一个点集中所有点的一些量的时候,可以建立一个超级源点和超级汇点,从多->多变成单->单 整体二分的时候,操作要可以撤销,才能保证复杂度,每一层到左边区间 ...

  7. scala资料总结,一些小技巧

    scala资料总结,一些小技巧 1.得到每种数据类型所表示的范围 Short.MaxValue 32767 Short.MinValue -32768 Int.MaxValue 2147483647 ...

  8. 前端网络、JavaScript优化以及开发小技巧

    一.网络优化 YSlow有23条规则,中文可以参考这里.这几十条规则最主要是在做消除或减少不必要的网络延迟,将需要传输的数据压缩至最少. 1)合并压缩CSS.JavaScript.图片,静态资源CDN ...

  9. 分享两个BPM配置小技巧

    1.小技巧 流程图修改后发布的话版本号会+1,修改次数多了之后可能会导致版本号很高,这个时候可以将流程导出,然后删除对应的流程包再导入,发布数据模型和流程图之后,版本清零 2.小技巧 有的同事入职后使 ...

随机推荐

  1. Codevs 3409 搬礼物

    时间限制: 1 s 空间限制: 64000 KB 题目等级 : 青铜 Bronze   题目描述 Description 小浣熊松松特别喜欢交朋友,今年松松生日,就有N个朋友给他送礼物.可是要把这些礼 ...

  2. poj2112 二分+floyd+多源多汇最大流

    /*此题不错,大致题意:c头牛去k个机器处喝奶,每个喝奶处最多容纳M头牛,求所有牛中走的最长路的 那头牛,使该最长路最小.思路:最大最小问题,第一灵感:二分答案check之.对于使最长路最短, 用fo ...

  3. django学习之- 动态验证码学习

    实例:通过前台和后台,实现用户登录页面动态图片验证码校验,图片验证码部分使用Pillow模块实现,作为单独学习部分记录. 前端: <!DOCTYPE html> <html lang ...

  4. 2015轻院校赛 D 社交网络(排列组合)

    http://acm.zznu.edu.cn/problem.php?id=1964 题目描述 输入 输出 样例输入 2 2 1 0 1 1 0 3 1 0 1 1 1 0 1 1 1 0 样例输出 ...

  5. 寒武纪camp Day4

    补题进度:7/11 A(博弈论) 略 B 待填坑 C(贪心) 题意: 一个序列是good的当且仅当相邻两个数字不相同.给出一个长度为n的数列,每个数字是ai.定义一种操作就是把a中某个元素拿到首位去, ...

  6. Java实验--统计字母出现频率及其单词个数

    本周的实验要求在之前实现统计单词的基础之上(可以见之前博客的统计单词的那个实验),对其进行修改成所需要的格式,统计字母出现频率的功能,并按照一定的格式把最终结果的用特定的格式在文本中显示出来 统计过程 ...

  7. CSS布局之BFC和IFC

    本文为原创,转载请注明出处: cnzt       文章:cnzt-p http://www.cnblogs.com/zt-blog/p/6708358.html <这是一篇css2-3的布局规 ...

  8. how to read openstack code: action extension

    之前我们看过了core plugin, service plugin 还有resource extension. resource extension的作用是定义新的资源.而我们说过还有两种exten ...

  9. ubuntu16.04LTS安装软件

    1.安装chrome 下载源加入到系统的源列表 sudo wget http://www.linuxidc.com/files/repo/google-chrome.list -P /etc/apt/ ...

  10. 获取当前时间 YYYY-MM-DD

    1.函数封装 /** * 获取当前时间 * 格式YYYY-MM-DD */ Vue.prototype.getNowFormatDate = function() { var date = new D ...