2015 多校联赛 ——HDU5305(搜索)
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
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.
3 3
1 2
2 3
3 1
4 4
1 2
2 3
3 4
4 1
2
求:朋友关系可离线可在线,要求每个人的离线朋友数等于在线朋友数,总共有多少种方法
先对入度判断,奇数直接不可能,然后再进行搜索
#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(搜索)的更多相关文章
- 2015 多校联赛 ——HDU5323(搜索)
Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 2015 多校联赛 ——HDU5348(搜索)
Problem Description As we all kown, MZL hates the endless loop deeply, and he commands you to solve ...
- 2015 多校联赛 ——HDU5334(构造)
Virtual Participation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- 2015 多校联赛 ——HDU5335(Walk out)
Walk Out Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total S ...
- 2015 多校联赛 ——HDU5302(构造)
Connect the Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 2015 多校联赛 ——HDU5294(最短路,最小切割)
Tricks Device Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- 2015 多校联赛 ——HDU5325(DFS)
Crazy Bobo Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Tota ...
- 2015 多校联赛 ——HDU5316(线段树)
Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...
- 2015 多校联赛 ——HDU5319(模拟)
Painter Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Su ...
随机推荐
- python3变量和数据类型
变量和数据类型 知识点 python 关键字 变量的定义与赋值 input() 函数 字符串的格式化 实验步骤 每一种编程语言都有它们自己的语法规则,就像我们所说的外语. 1. 关键字和标识符 ...
- JAVA接口基础知识总结
1:是用关键字interface定义的. 2:接口中包含的成员,最常见的有全局常量.抽象方法. 注意:接口中的成员都有固定的修饰符. 成员变量:public static final 成员方法 ...
- 配置SpringAop时需要用到的AspectJ表达式
Aspectj切入点语法定义 在使用spring框架配置AOP的时候,不管是通过XML配置文件还是注解的方式都需要定义pointcut"切入点" 例如定义切入点表达式 execu ...
- Android接受验证码自动填入功能(源码+已实现+可用+版本兼容)
实际应用开发中,会经常用到短信验证的功能,这个时候如果再让用户就查看短信.然后再回到界面进行短信的填写,难免有多少有些不方便,作为开发者.本着用户至上的原则我们也应该来实现验证码的自动填写功能,还有一 ...
- img加载卡顿,解决办法
我觉得我在这个项目里遇到了太多的第一次.比如上一篇博文:在在360.UC等浏览器,img不加载原因. 当前情况是:图片加载缓慢,图片加载时出现卡顿. 上图:我缩放了图片,估计有点变形.能说明情况就行, ...
- python全栈开发-Day13 内置函数
一.内置函数 注意:内置函数id()可以返回一个对象的身份,返回值为整数. 这个整数通常对应与该对象在内存中的位置,但这与python的具体实现有关,不应该作为对身份的定义,即不够精准,最精准的还是以 ...
- day-4 python多进程编程知识点汇总
1. python多进程简介 由于Python设计的限制(我说的是咱们常用的CPython).最多只能用满1个CPU核心.Python提供了非常好用的多进程包multiprocessing,他提供了一 ...
- Python format 格式化函数
str.format() 格式化字符串的函数 str.format(),它增强了字符串格式化的功能. 基本语法是通过 {} 和 : 来代替以前的 % format 函数可以接受不限个参数,位置可以不按 ...
- MySQL关系表查询两个表的数据
如下,有四张表:游戏类型表,游戏表,点卡和游戏关系表,点卡表 CREATE TABLE `gamesType`( `tId` INT AUTO_INCREMENT NOT NULL PRIMARY K ...
- kafka--producer 发布消息
1. 写入方式 producer 采用 push 模式将消息发布到 broker,每条消息都被 append 到 patition 中,属于顺序写磁盘(顺序写磁盘效率比随机写内存要高,保障 kafka ...