HDU 5556 最大独立集】的更多相关文章

这题主要有了中间的一些连通块的限制,不太好直接用二分图最大独立集做.考虑到图比较小,可以作补图求最大团来求解. #include <iostream> #include <vector> #include <algorithm> #include <string> #include <string.h> #include <stdio.h> #include <queue> #include <stack> #…
题意:一个动物园里有N只猫和K只狗,一些小朋友来参观,他们如果喜欢狗就不喜欢猫,喜欢猫就不喜欢狗,园长想要移走一些动物,如果,移走的是某个小朋友不喜欢的,而喜欢的没被移走,该小朋友就会高兴,求移动的数目使得最多的小朋友开心 Sample Input 1 1 2 //1个猫1个狗2个小朋友 C1 D1 //一号小朋友喜欢c1,讨厌d1 D1 C1 1 2 4 C1 D1 C1 D1 C1 D2 D2 C1     转换为最大独立集做 #include<cstdio> #include<io…
Farmer John and his brothers have found a new land. They are so excited and decide to build new farms on the land. The land is a rectangle and consists of N×MN×Mgrids. A farm consists of one or more connected grids. Two grids are adjacent if they sha…
Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10500    Accepted Submission(s): 4849 Problem Description the second year of the university somebody started a study on the roman…
Land of Farms Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 539    Accepted Submission(s): 177 Problem Description Farmer John and his brothers have found a new land. They are so excited and d…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 有n个同学,格式ni:(m) n1 n2 n3表示同学ni有缘与n1,n2,n3成为情侣,求集合中不存在有缘成为情侣的同学的最大同学数. 独立集(图的顶点集的子集,其中任意两点不相邻) 二分图中 最大独立集 = 顶点个数 - 最大匹配数 因为男女不知道,将一个人拆成两个性别,求最大匹配后,除以2就行了. 这种做法比较难理解. #include <iostream> #include <…
HDU 1068 :题目链接 题意:一些男孩和女孩,给出一些人物关系,然后问能找到最多有多少个人都互不认识. 转换一下:就是大家都不认识的人,即最大独立集合 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <math.h> #define init(a) memset(a,…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 题目大意:有n个人,一些人认识另外一些人,选取一个集合,使得集合里的每个人都互相不认识,求该集合中人的最大个数. 解题思路:这题就是求最大独立集,但是这并不是两个集合,而是一个集合,所以求出最大匹配后需要/2,然后代公式:最大独立集=N-最大匹配. 代码: #include<iostream> #include<cstdio> #include<cstring> #i…
Cat VS Dog Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 3829 Description The zoo have N cats and M dogs, today there are P children visiting the zoo, each child has a like-animal and a dislik…
http://acm.hdu.edu.cn/showproblem.php?pid=1068 因为没有指定性别,所以要拆点,把i拆分i和i’ 那么U=V-M (M是最大匹配,U最大独立集,V是顶点数) 2U=2V-2M  所以 U=n-M'/2. (没怎么看明白)  但是不这样会wa. #include <iostream> #include <cstdio> #include <cmath> #include <vector> #include <c…