DFS HDU 5305 Friends】的更多相关文章

题目传送门 /* 题意:每个点都要有偶数条边,且边染色成相同的两部分,问能有多少种染色方法 DFS+剪枝:按照边数来DFS,每种染色数为该点入度的一半,还有如果点不是偶数边就不DFS 这是别人的DFS,写的精简强大,膜拜之... */ #include <cstdio> #include <algorithm> #include <cstring> #include <vector> using namespace std; ; const int INF…
Friends 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5305 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 (most…
题意: 给定n个人,m对朋友关系,如果对于每个人,只能刚好选择其所有朋友中的一半的人进行聊天(只是我和我的朋友,不是我的朋友和我的朋友),那么有多少种情况?只要一个选择不同,视为不同情况. 思路: 比如我在14个朋友中选择了7个跟我聊天,那么另外7人已经完全与我没干系,而和我聊天的7个朋友,也已经和我聊天了,即我们配对了,共7对,他所选择的那一半的人中也必须有我. 其实只考虑所给的m条边就行了.如果是奇数对关系,必定有人是奇数个朋友,那么也就0种情况.如果是偶数条边,还得判断每个人是否都是偶数个…
Friends Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 878    Accepted Submission(s): 422 Problem Description There are n people and m pairs of friends. For every pair of friends, they can cho…
Friends Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 297    Accepted Submission(s): 127 Problem Description There are n people and m pairs of friends. For every pair of friends, they can cho…
依据题意的话最多32条边,直接暴力的话 2 ^ 32肯定超时了.我们能够分两次搜索时间复杂度降低为 2 * 2  ^ 16 唯一须要注意的就是对眼下状态的哈希处理. 我採用的是 十进制表示法 跑的还是比較快的,可能是用STL函数的原因添加了一些常数复杂度. #include<map> #include<vector> #include<cstdio> #include<cstring> #include<algorithm> using name…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5305 题意:给你n个人,m条关系,关系可以是online也可以是offline,让你求在保证所有人online关系的朋友和offline关系的朋友相等的情况下,这样的情况有多少种. 思路:因为online关系和offline关系的人数相等,而且m最多才28,所以只要枚举每个人的一半的关系是否符合要求即可,而且根据题意m是奇数或者有一个人的总关系为奇数那么就没有符合要求的情况,这样可以排除很多情况.…
http://acm.hdu.edu.cn/showproblem.php?pid=1016 #include <iostream> using namespace std; int a[30],n,used[40]; int is_prime(int x) { for(int i=2;i<x; i++) if(x%i==0) return 0; return 1; } void dfs(int cur) { int i; if(cur==n && is_prime(a[…
变形课 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 19133    Accepted Submission(s): 6892 Problem Description 呃......变形课上Harry碰到了一点小麻烦,因为他并不像Hermione那样能够记住所有的咒语而随意的将一个棒球变成刺猬什么的,但是他发现了变形咒语的一个统一规…
每一次比赛的时候脑子都卡顿, 这次更离谱,我居然二进制枚举边,这么大的复杂度.而且剪不了枝 后来学长说着是道爆搜.搜每一条边.恍然大悟. 仅仅须要剪掉点的度数是奇数的时候,或者他的线上朋友或线下朋友大于等于度数的1/2时候的枝, 跑了15ms #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int x[100],y[100]; int of[100],on[10…