hdu-1067(最大独立集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068
题意:一个男生集合和一个女生集合,给出两个集合之间一一对应的关系,求出两个集合中最大独立集的点数。
思路:在二分图中,最大独立集的点数=顶点数-最大匹配数/2;
求二分图的最大匹配数需要用匈牙利算法(主要思想是求:增广路径,增广路径的数目=最大匹配数)。
参考文章:https://blog.csdn.net/u011032846/article/details/38031825
最大独立集:https://blog.csdn.net/Richard_for_OI/article/details/79520470
二分图的最大匹配问题:https://blog.csdn.net/x_y_q_/article/details/51920683
想了好久,还是看代码吧。
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- using namespace std;
- const int maxn = ;
- int n,mx[maxn],my[maxn],vis[maxn],e[maxn][maxn];
- int path(int i) //i是结合x中的节点
- {
- int j;
- for(j=;j<n;j++) //就是集合y中的节点
- {
- if(e[i][j]&&!vis[j])
- {
- vis[j]=;
- if(my[j]==-||path(my[j])) //节点未访问或者访问到取反后的节点,两者都不符合,则说明再也找不到增广路径,结束。
- {
- //取反
- my[j]=i;
- mx[i]=j;
- return ;
- }
- }
- }
- return ;
- }
- int hungry() //匈牙利算法,求最大匹配
- {
- int res=;
- memset(mx,-,sizeof(mx));
- memset(my,-,sizeof(my));
- for(int i=;i<n;i++)
- {
- if(mx[i]==-)
- {
- memset(vis,,sizeof(vis));
- res+=path(i);
- }
- }
- return res;
- }
- int main(void)
- {
- int a,b,m,i;
- while(~scanf("%d",&n))
- {
- memset(e,,sizeof(e));
- for(i=;i<n;i++)
- {
- scanf("%d: (%d)",&a,&m);
- while(m--)
- {
- scanf("%d",&b);
- e[a][b]=;
- }
- }
- printf("%d\n",n-hungry()/);
- }
- return ;
- }
hdu-1067(最大独立集)的更多相关文章
- HDU 1067 Gap
HDU 1067 Gap Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) P ...
- [hdu 1067]bfs+hash
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1067 queue里面果然不能放vector,还是自己写的struct比较省内存…… #include& ...
- 【hdu 1067】Gap
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission( ...
- HDU 5556 最大独立集
这题主要有了中间的一些连通块的限制,不太好直接用二分图最大独立集做.考虑到图比较小,可以作补图求最大团来求解. #include <iostream> #include <vecto ...
- hdu 3289 最大独立集
题意:一个动物园里有N只猫和K只狗,一些小朋友来参观,他们如果喜欢狗就不喜欢猫,喜欢猫就不喜欢狗,园长想要移走一些动物,如果,移走的是某个小朋友不喜欢的,而喜欢的没被移走,该小朋友就会高兴,求移动的数 ...
- hdu.1067.Gap(bfs+hash)
Gap Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- HDU - 1067 Gap (bfs + hash) [kuangbin带你飞]专题二
题意: 起初定28张卡牌的排列,把其中11, 21, 31, 41移动到第一列,然后就出现四个空白,每个空白可以用它的前面一个数的下一个数填充,例如43后面的空格可以用44填充,但是47后面即 ...
- hdu 1068(最大独立集)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- KUANGBIN带你飞
KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题 //201 ...
- [kuangbin带你飞]专题1-23题目清单总结
[kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 Fli ...
随机推荐
- XE6 c++builder Edit垂直居中
class TMyEdit : public Vcl::Stdctrls::TEdit { virtual void __fastcall CreateParams(TCreateParams& ...
- VBA 使用区域和当前区域
VBA 选择使用区域 Sub Select_UsedRange() ActiveSheet.Range(ActiveSheet.Cells(1, 1), ActiveSheet.UsedRange). ...
- span width不起作用,border 无效
span属于内联元素,因此width对内联元素不起作用. 需要设置display:inline-block;使其成为内联级块级元素: border不起作用,主要是未设置border-style:sol ...
- TEXT 5 Stuff of dreams
TEXT 5 Stuff of dreams 梦想的精粹 Feb 16th 2006 | CORK AND LONDON From The Economist print edition (译者注:本 ...
- layoutSubviews相关总结
ios layout机制相关方法 - (CGSize)sizeThatFits:(CGSize)size - (void)sizeToFit ------- - (void)layoutSubview ...
- C#整合VS2010和NUnit
软件下载 .Net单元测试工具 NUnit下载:http://www.nunit.org/index.php?p=download,最新的为NUnit-2.6.0.12051.msi,下载安装. VS ...
- Installation failed with message INSTALL_CANCELED_BY_USER.
Installation failed with message INSTALL_CANCELED_BY_USER. It is possible that this issue is resolve ...
- sql重复数据只取一条记录
1.SQL SELECT DISTINCT 语句 在表中,可能会包含重复值.这并不成问题,不过,仅仅列出不同(distinct)的值. 关键词 DISTINCT 用于返回唯一不同的值. 语法: SEL ...
- 奇偶数判断2(if else+switch语句)
public class 奇偶数判断2 { public static void main(String [] agrs){ float s = 17f; //定义浮点型数据s float h = s ...
- C++中纯虚函数
1.纯虚函数 virtual ReturnType Function()= 0; 纯虚函数可以让类先具有一个操作名称,而没有操作内容,让派生类在继承时再去具体地给出定义.凡是含有纯虚函数的类叫做抽象类 ...