HDU 5305 Friends(简单DFS)
Friends
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 878 Accepted Submission(s): 422
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.
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.
2
3 3
1 2
2 3
3 1
4 4
1 2
2 3
3 4
4 1
0
2
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h> using namespace std; int n,m;
int num[10];
int pa[10],pb[10];
int sum; struct node
{
int x;
int y;
}q[100100]; void DFS(int p)
{
//printf("p = %d\n",p);
if(p == m)
{
sum++;
return ;
}
int x = q[p].x;
int y = q[p].y;
if(pa[x] && pa[y])
{
pa[x]--;
pa[y]--;
DFS(p+1);
pa[x]++;
pa[y]++;
}
if(pb[x] && pb[y])
{
pb[x]--;
pb[y]--;
DFS(p+1);
pb[x]++;
pb[y]++;
}
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
sum = 0;
memset(num,0,sizeof(num));
scanf("%d%d",&n,&m);
int x,y;
for(int i=0;i<m;i++)
{
scanf("%d%d",&x,&y);
q[i].x = x;
q[i].y = y;
num[x]++;
num[y]++;
}
int flag = 0;
for(int i=1;i<=n;i++)
{
pa[i] = num[i]/2;
pb[i] = num[i]/2;
if(num[i]%2 == 1)
{
flag = 1;
break;
}
}
if(flag)
{
printf("0\n");
continue;
}
DFS(0);
printf("%d\n",sum);
}
return 0;
}
HDU 5305 Friends(简单DFS)的更多相关文章
- hdu - 1704 Rank(简单dfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1704 遇到标记过的就dfs,把隐含的标记,最后计数需要注意. #include <cstdio> # ...
- HDU 5305 Friends(dfs)
Friends Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Su ...
- HDOJ(HDU).1035 Robot Motion (DFS)
HDOJ(HDU).1035 Robot Motion [从零开始DFS(4)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DF ...
- Counting Cliques HDU - 5952 单向边dfs
题目:题目链接 思路:这道题vj上Time limit:4000 ms,HDU上Time Limit: 8000/4000 MS (Java/Others),且不考虑oj测评机比现场赛慢很多,但10月 ...
- HDU 1401 Solitaire 双向DFS
HDU 1401 Solitaire 双向DFS 题意 给定一个\(8*8\)的棋盘,棋盘上有4个棋子.每一步操作可以把任意一个棋子移动到它周围四个方向上的空格子上,或者可以跳过它四个方向上的棋子(就 ...
- HDU 2085 核反应堆 --- 简单递推
HDU 2085 核反应堆 /* HDU 2085 核反应堆 --- 简单递推 */ #include <cstdio> ; long long a[N], b[N]; //a表示高能质点 ...
- Red and Black(简单dfs)
Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDOJ(HDU).2660 Accepted Necklace (DFS)
HDOJ(HDU).2660 Accepted Necklace (DFS) 点我挑战题目 题意分析 给出一些石头,这些石头都有自身的价值和重量.现在要求从这些石头中选K个石头,求出重量不超过W的这些 ...
- HDOJ(HDU).1045 Fire Net (DFS)
HDOJ(HDU).1045 Fire Net [从零开始DFS(7)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HD ...
- HDOJ(HDU).1241 Oil Deposits(DFS)
HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
随机推荐
- android视频播放器系列(二)——VideoView
最近在学习视频相关的知识,现在也是在按部就班的一步步的来,如果有同样需求的同学可以跟着大家一起促进学习. 上一节说到了可以使用系统播放器以及浏览器播放本地以及网络视频,但是这在很大程度上并不能满足我们 ...
- MySQL与MongoDB的操作对比
MySQL与MongoDB都是开源的常用数据库,但是MySQL是传统的关系型数据库,MongoDB则是非关系型数据库,也叫文档型数据库,是一种NoSQL的数据库.它们各有各的优点,关键是看用在什么地方 ...
- 学习RFT之:TestObject.find方法的了解与使用
第一部分:了解TestObject.find 一.TestObject.find方法的作用 1.测试过程中动态的找到测试对象(控件.标签等),使我们的测试用例不再依赖RFT自带的对象地图(Object ...
- PAT甲级考前整理(2019年3月备考)之一
转载请注明出处:https://www.cnblogs.com/jlyg/p/7525244.html 终于在考前,刷完PAT甲级131道题目,不容易!!!每天沉迷在刷题之中而不能超脱,也是一种 ...
- OpenGL坐标系之间的转换 http://blog.csdn.net/sac761/article/details/52179585
1. OpenGL 渲染管线 OpenGL渲染管线分为两大部分,模型观测变换(ModelView Transformation)和投影变换(Projection Transformation).做个比 ...
- CAD执行一个带参数的命令(com接口VB语言)
主要用到函数说明: MxDrawXCustomFunction::Mx_SendStringToExecute 执行一个带参数的命令.详细说明如下: 参数 说明 CString sCmaName 命令 ...
- 【转载】Appium环境搭建(Windows版)
注:appium安装到C盘,node.js安装到C盘 一.安装node.js 1.到官网下载node.js:https://nodejs.org/en/download/ 2.获取到安装文件后,直接双 ...
- 洛谷——P3369 【模板】普通平衡树(splay)(基础splay,维护一些神奇的东东)
P3369 [模板]普通平衡树 平衡树大法好,蒟蒻(博主)最近正在收集高级数据结构的碎片,企图合成数据结构的元素之力来使自己的RP++... 您需要写一种数据结构(可参考题目标题),来维护一些数,其中 ...
- Docker从入门到实践
一般说来 SPA 的项目我们只要启一个静态文件 Server 就可以了,但是针对传统项目就不一样了,一个项目会依赖很多服务端程序.之前我们的开发模式是在一台开发机上部署开发环境,所有人都在这台开发机上 ...
- 1. Jenkins 入门使用
1. 下载jenkins https://pkg.jenkins.io/redhat-stable/ sudo wget -O /etc/yum.repos.d/jenkins.repo https: ...