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 ...
随机推荐
- python array 使用创建10万浮点数
from array import array from random floats = array('d',random((for i in range(10**7)) fp = open('flo ...
- CPP链表示例
#include<iostream> #include<stdlib.h> using namespace std; typedef struct Student_data { ...
- Storm概念讲解和工作原理介绍
Strom的结构 Storm与传统关系型数据库 传统关系型数据库是先存后计算,而storm则是先算后存,甚至不存 传统关系型数据库很难部署实时计算,只能部署定时任务统计分析窗口数据 ...
- Jmeter读取文件中的值《一》
此篇主要是对应上一章节的呼应,上一篇中讲到将返回值写入文件,这个值如果在下一个接口中用到, 那么我们需要去从文件中读取数据,这是我们该如何操作? 一.测试计划中添加CSV Data Set Confi ...
- 调用WCF时,调用已超过传入消息(65536)的最大消息大小配额。若要增加配额,请使用相应绑定。
解决方案: 其实只要在客户端配置文件中加上如下紫色粗体属性( maxReceivedMessageSize): <?xml version="1.0" encoding=&q ...
- pdf解析与结构化提取
#PDF解析与结构化提取##PDF解析对于PDF文档,我们选择用PDFMiner对其进行解析,得到文本.###PDFMinerPDFMiner使用了一种称作lazy parsing的策略,只在需要的时 ...
- Autofac 简单示例
公司不用任何IOC,ORM框架,只好自己没事学学. 可能有些语言描述的不专业 希望能有点用 namespace Autofac { class Program { //声明一个容器 private s ...
- 自动化服务部署(二):Linux下安装jenkins
jenkins是一个Java开发的开源持续集成工具,广泛用于项目开发,具有自动化构建.测试和部署等功能,它的运行需要Java环境. 上篇博客介绍了Linux下安装JDK的步骤,这篇博客,介绍下Linu ...
- SpringCloud的Hystrix(五) Hystrix机制
参考链接:http://www.jianshu.com/p/e07661b9bae8 一.前言 大型复杂的分布式系统中,高可用相关的技术架构非常重要.高可用架构非常重要的一个环节,就是如何将分布式系统 ...
- SpringBoot的配置文件加载顺序和使用方式
1.bootstrap.properties bootstrap.properties 配置文件是由"根"上下文优先加载,程序启动之初就感知 如:Spring Cloud Conf ...