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. 【ZJOI2017 Round1练习&BZOJ4765】D1T3 普通计算姬(主席树,分块)

    题意: 思路:分块 使用树状数组维护sum[i]的前缀和 使用主席树维护root到u的路径上点的编号出现的个数 每次操作如果是修改就加入队列 如果是询问,考虑块内操作对询问的影响,每次在x点加上y会使 ...

  2. phpstorm的破解

    按照PHPstorm进入如下页面: 然后继续单击License  server  输入:http://www.0-php.com:1017    PHPstorm完美运行!!!!!

  3. django学习之- CSRF及中间件

    CSRF # 表示django全局发送post请求均需要字符串验证功能:防止跨站请求伪造的功能工作原理:客户端访问服务器端,在服务器端正常返回给客户端数据的时候,而外返回给客户端一段字符串,等到客户端 ...

  4. UESTC 1087 【二分查找】

    问了某明==shit 中文题意不解释. 因为数据的范围是1e9以内的所以我们可以通过二分的方法枚举可能的中位数. 用二分法每次判断某一数字比中位数大还是比中位数小. 判断方法是,枚举以第n个数为起点的 ...

  5. HDU 5360 【优先队列+贪心】

    题意: 给定N个无序区间. 对合法区间的定义是: 在这个区间之前已经选出了至少l个合法区间,最多选出了r个合法区间.则该区间为合法区间. 输出最多能挑选出多少个合法区间,并输出合法区间的数量. 思路: ...

  6. 打开input输入的时候,css中position:absolute/fixed定位的时候,定位元素上移问题解决

    1.异常代码 <style> .box{ min-height: 100vh; width: 100%; position: relative; } .position{ position ...

  7. 第三方APP集成微信登陆功能详解

    授权后接口调用(UnionID) 通过code获取access_token 接口说明 通过code获取access_token的接口. 请求说明 http请求方式: GET https://api.w ...

  8. 利用NSA的MS17-010漏洞利用工具实现Win 7和Win Server 2008系统入侵

    影子经纪人(Shadow Brokers)最近陆续曝光的NSA网络武器令人震惊,尽管这些工具是否出自国家级别黑客团队之手尚不清楚,但至少存在一个可以说明问题的事实:这些漏洞利用工具都能有效运行,且具有 ...

  9. Linux 网络工具

    1 nethogs nethogs 是一个免费的工具,当要查找哪个 PID (注:即 process identifier,进程 ID) 给你的网络流量带来了麻烦时,它是非常方便的.它按每个进程来分组 ...

  10. Office EXCEL 2010如何启用宏编辑器,打开VB编辑器

    文件-选项-主选项卡,勾选开发工具 然后在开发工具中找到Visual Basic编辑器,打开代码