Friends

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 163    Accepted Submission(s): 61

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. 
 
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

求:朋友关系可离线可在线,要求每个人的离线朋友数等于在线朋友数,总共有多少种方法

先对入度判断,奇数直接不可能,然后再进行搜索

#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <vector>
using namespace std; struct node
{
int u,v;
} pnode[50]; int in[10];
int c[10],c2[10];
int ans,n,m;
int num,tem; void dfs(int u)
{
if(u == m+1)
{
for(int i = 1; i <= n; i++)
if(c[i] != c2[i])
return;
ans++;
return ;
}
int a = pnode[u].u;
int b = pnode[u].v;
if(c[a] < in[a]/2 && c[b] < in[b]/2)
{
c[a] ++;
c[b] ++;
dfs(u+1);
c[a]--;
c[b]--;
}
if(c2[a] < in[a]/2 && c2[b] < in[b]/2)
{
c2[a] ++;
c2[b] ++;
dfs(u+1);
c2[a]--;
c2[b]--;
}
return;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int flag = 0;
scanf("%d%d",&n,&m);
memset(in,0,sizeof(in));
for(int i = 1; i <= m; i++)
{
scanf("%d%d",&pnode[i].u,&pnode[i].v);
in[pnode[i].u]++;
in[pnode[i].v]++;
}
memset(c,0,sizeof(c));
memset(c2,0,sizeof(c2));
for(int i = 1; i <= n; i++)
{
if(in[i] % 2 == 1)
{
flag = 1;
break;
}
}
if(flag){
printf("0\n");
continue;
}
ans = 0;
dfs(1); printf("%d\n",ans); }
return 0;
}

  

2015 多校联赛 ——HDU5305(搜索)的更多相关文章

  1. 2015 多校联赛 ——HDU5323(搜索)

    Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  2. 2015 多校联赛 ——HDU5348(搜索)

    Problem Description As we all kown, MZL hates the endless loop deeply, and he commands you to solve ...

  3. 2015 多校联赛 ——HDU5334(构造)

    Virtual Participation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  4. 2015 多校联赛 ——HDU5335(Walk out)

    Walk Out Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total S ...

  5. 2015 多校联赛 ——HDU5302(构造)

    Connect the Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  6. 2015 多校联赛 ——HDU5294(最短路,最小切割)

    Tricks Device Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  7. 2015 多校联赛 ——HDU5325(DFS)

    Crazy Bobo Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Tota ...

  8. 2015 多校联赛 ——HDU5316(线段树)

    Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...

  9. 2015 多校联赛 ——HDU5319(模拟)

    Painter Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Su ...

随机推荐

  1. 操作 numpy 数组的常用函数

    操作 numpy 数组的常用函数 where 使用 where 函数能将索引掩码转换成索引位置: indices = where(mask) indices => (array([11, 12, ...

  2. 使用Python定制词云

    一.实验介绍 1.1 实验内容 在互联网时代,人们获取信息的途径多种多样,大量的信息涌入到人们的视线中.如何从浩如烟海的信息中提炼出关键信息,滤除垃圾信息,一直是现代人关注的问题.在这个信息爆炸的时代 ...

  3. django搭建web (一)

    建立工程 django-admin.py startproject project_name 建立app python manage.py startapp app_name 将app添加进工程中 在 ...

  4. Python choice() 函数

    Python choice() 函数  Python 数字 描述 choice() 方法返回一个列表,元组或字符串的随机项. 语法 以下是 choice() 方法的语法: import random ...

  5. 几种Java的JSON解析库速度对比

    java中哪个JSON库的解析速度是最快的? JSON已经成为当前服务器与WEB应用之间数据传输的公认标准,不过正如许多我们所习以为常的事情一样,你会觉得这是理所当然的便不再深入思考 了.我们很少会去 ...

  6. codevs 3981 动态最大子段和

    3981 动态最大子段和 http://codevs.cn/problem/3981/    题目等级 : 钻石 Diamond   题目描述 Description 题目还是简单一点好... 有n个 ...

  7. Scala 快速入门

     Scalable 编程语言 纯正的的面向对象语言 函数式编程语言 无缝的java互操作 scala之父 Martin Odersky 1. 函数式编程 函数式编程(functional progr ...

  8. Syabse数据库无法启动的解决方案

    在探讨本问题之前,首先要为大家解释一下Syabse数据库本身.Syabse数据库应用和本身的架构相对而言都相对比较复杂,多数技术人员及公司对Sybase数据库底层结构和运行机制也处于并非完全了解的阶段 ...

  9. margin-top导致父标签偏移问题

    从一个大神博客中看到这句话: 这个问题发生的原因是根据规范,一个盒子如果没有上补白(padding-top)和上边框(border-top),那么这个盒子的上边距会和其内部文档流中的第一个子元素的上边 ...

  10. JAVA_SE基础——34.static修饰成员变量

    需求:描述一下学校的学生.  特点:都是中国人.... 测试代码1: class Student{ String name; String country = "中国"; //国籍 ...