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 ...
随机推荐
- 201621123031 《Java程序设计》第4周学习总结
Week04-面向对象设计与继承 1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 关键词:继承.覆盖.多态.抽象 1.2 尝试使用思维导图将这些关键词组织起来. 1.3 可选: ...
- 结合Socket实现DDoS攻击
一.实验说明 1. 实验介绍 通过上一节实验的SYN泛洪攻击结合Socket实现DDoS攻击. 2. 开发环境 Ubuntu Linux Python 3.x版本 3. 知识点 本次实验将涉及以下知识 ...
- Django 模版语法
一.简介 模版是纯文本文件.它可以产生任何基于文本的的格式(HTML,XML,CSV等等). 模版包括在使用时会被值替换掉的 变量,和控制模版逻辑的 标签. {% extends "base ...
- Django-rest-framework源码分析----权限
添加权限 (1)API/utils文件夹下新建premission.py文件,代码如下: message是当没有权限时,提示的信息 # utils/permission.py class SVIPPr ...
- JAVA_SE基础——42.final修饰符
高手勿喷~ final关键字可用于修饰类.变量和方法,它有"这是无法改变的"或者"最终"的含义,因此被final修饰的类.变量和方法将具有以下特征: 1.fin ...
- 有货前端 Web-APM 实践
有货前端 Web-APM 实践 0 背景 有货电商技术架构上采用的是前后端分离,前端是主要以业务展示和接口聚合为主,拥有自己的 BFF (Backend For Frontend),以 nodejs ...
- ssh框架-Struts2(二)
上篇文章我们了解了怎么配置struts.xml文件,以及前端控制器配置怎么配置,,Action进阶,Result结果配置,Struts2中的Servlet的API的访问,以及怎么获得请求参数.今天我们 ...
- YML(1)什么是 YML
YAML(IPA: /ˈjæməl/,尾音类似camel骆驼) YAML 是一个可读性高,用来表达资料序列的编程语言. YAML参考了其他多种语言,包括:XML.C语言.Python.Perl以及电子 ...
- python网络爬虫与信息提取 学习笔记day1
Day1: 安装python之后,为其配置requests第三方库,并爬取百度主页内容. 语句解释: r.status_code检测请求的状态码,如果状态码为200,则说明访问成功,否则,则说明访问失 ...
- idea的spring boot项目,运行时不要显示在dashboard中
将对应项目的上图配置,取消勾选即可.