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 ...
随机推荐
- 每日冲刺报告-Day4
敏捷冲刺报告--Day4 情况简介 今天完成前端后端任务对接, GUI主体编写 任务进度 赵坤: 完成后端爬虫 李世钰: 前后端对接, GUI编写 黄亦薇:召集小组成员开会,帮助查找资料,寻找BUG ...
- 团队作业7——第二次项目冲刺(Beta版本12.06)
项目每个成员的进展.存在问题.接下来两天的安排. 已完成的内容:队员每个人提出对接下来需要做的事情的看法和意见,将需要做的任务更新到了leangoo中进行管理,产品完成了界面优化的设计,测试复现了之前 ...
- choose the max from numbers, use scanf and if else (v1:21.9.2017,v2:23.9.2017)
#include<stdio.h> int main(){ int a,b,c,max; printf("请输入一个数值: "); scanf("%d&quo ...
- C语言-第一次作业
题目6-1 计算两数的和与差 1.设计思路 (1)主要描述题目算法 第一步:看主函数知道程序输入浮点型变量a,b,通过函数计算输出和与差. 第二步:函数部分将a赋值op1,b赋值op2,&su ...
- JAVA委托事件处理机制
1)事件:用户对程序的某一种功能性操作. Java中的事件主要有两种: 1.组件类事件 componentEvent.ContainerEvent.WindowEvent.FocusEvent.Pai ...
- bzoj千题计划217:bzoj2333: [SCOI2011]棘手的操作
http://www.lydsy.com/JudgeOnline/problem.php?id=2333 读入所有数据,先模拟一遍所有的合并操作 我们不关心联通块长什么样,只关心联通块内有谁 所以可以 ...
- JS页面跳转的常用方法整理.
<script type="text/javascript"> //js页面跳转 function showtabs() { window.location.href ...
- 不允许用(a+b)/2这种方式求两个数的均值;如下程序在Linux和32位集成开发环境中运行
#define MAX(a,b) ((a)>(b)?(a):(b)) #include<stdio.h> int main() { int a = 10; int b = 20; i ...
- redis命令详解
redis中添加key value元素:set key value; 获取元素:get key ; redis中添加集合:lpush key value1 value2 value ...
- redux的使用过程
1.redux是react的状态管理工具,可以用来存放公共数据,因此也可用来作为组件间参数传递的方法. 2.组件传参,需要有一个公共的父组件.在父组件中引入Provider.通过Provider将 ...