2015 多校联赛 ——HDU5305(搜索)
来源:互联网 发布:红牛为什么那么贵 知乎 编辑:程序博客网 时间:2024/05/29 04:54
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
23 31 22 33 14 41 22 33 44 1
Sample Output
02
Source
2015 Multi-University Training Contest 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;}
0 0
- 2015 多校联赛 ——HDU5305(搜索)
- 2015 多校联赛 ——HDU5323(搜索)
- 2015 多校联赛 ——HDU5348(搜索)
- hdu5305搜索
- 2015 多校联赛 ——HDU5289(二分+ST)
- 2015多校联赛 ——HDU5288(数学)
- 2015 多校联赛 ——HDU5299(树删边)
- 2015 多校联赛 ——HDU5303(贪心)
- 2015 多校联赛 ——HDU5301(技巧)
- 2015 多校联赛 ——HDU5319(模拟)
- 2015 多校联赛 ——HDU5316(线段树)
- 2015 多校联赛 ——HDU5325(DFS)
- 2015 多校联赛 ——HDU5302(构造)
- 2015 多校联赛 ——HDU5335(Walk out)
- 2015 多校联赛 ——HDU5334(构造)
- 2015 多校联赛 ——HDU5344(水)
- 2015 多校联赛 ——HDU5349(水)
- 2015 多校联赛 ——HDU5350(huffman)
- 简单的 iOS 表格
- Babelfish
- 雁回山后山成为我最常去的地方
- gtk实现alt+f4功能
- 1016. Phone Bills (25)
- 2015 多校联赛 ——HDU5305(搜索)
- CF 559A(Gerald's Hexagon-几何割补法)
- ocp 047-92 Evaluate the following expression using meta. character for regular expression:'[^Ale|ax
- 关于Posix的消息队列
- 简单的i++ ++i实现
- 进程间通信-共享存储
- poj 2594 Treasure Exploration(最小路径覆盖/二分最大匹配)
- GCD,快速GCD,扩展GCD
- Git-Common-Usage