2015 多校联赛 ——HDU5305(搜索)
2015-07-24 17:07
218 查看
Friends
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 163 Accepted Submission(s): 61
Problem DescriptionThere 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
2
3 3
1 2
2 3
3 1
4 4
1 2
2 3
3 4
4 1
Sample Output
0
2
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; }
相关文章推荐
- 1016. Phone Bills (25)
- 纯CSS绘制三角形(各种角度)
- 2015 多校联赛 ——HDU5305(搜索)
- 自定义alertview
- freemarker跳出循环
- 判断有环的链表相交和第一个公共节点(全面)
- Java的服务端程序性能问题调查方法
- 结构化程序设计方法
- 土木工程转行IOS的点点滴滴,没受伤是不知道回头滴
- C语言部分题目解析
- 【Java】集合框架
- spring 实现AOP的4种方式
- 通过WiFi连接真机进行appium测试
- 优化数据页面(20)——提供筛选
- C语言流程控制之循环笔记
- 我现在的心情!!!
- android jni入门基础
- Kafka 对比 ActiveMQ
- Activity跳转实例
- UVA 4080 Warfare And Logistics 战争与物流 (最短路树,变形)