随笔分类 -  二分图最大匹配

 
HDU 3335
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3335题意:在给出的n个数中找出一个集合,使得其中的数互不整除,求该集合最大的元素数量首先要对输入的数去重,输入的数是64位的,开始没用__int64坑了好久一上来我以为是求二分图最大独立集,利用相反的关系建边(整... 阅读全文
posted @ 2014-11-22 22:25 LegendaryAC 阅读(406) 评论(0) 推荐(0)
HDU 4160
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4160大娃娃可以套在小娃娃外面(各边严格小),问最后最少得到几个娃娃题目中的娃娃可以看做点,嵌套关系可以看做有向的路径,这样发现这题就是一个裸的最小路径覆盖问题#include #include #include ... 阅读全文
posted @ 2014-11-22 21:02 LegendaryAC 阅读(212) 评论(0) 推荐(0)
HDU 1350
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1350给m个顾客的乘车信息,表示几点前上车,要从一个坐标点到达另一个坐标点,花费的时间是两点的曼哈顿距离,两次换乘至少间隔1分钟(具体看样例),求最少的司机数目把每位顾客看成一个点,如果该司机可以在接完a顾客后接到... 阅读全文
posted @ 2014-11-22 20:38 LegendaryAC 阅读(284) 评论(0) 推荐(0)
HDU 5093
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=5093二分图最大匹配的经典建图模型,行列分别缩点(连起来的'*' & 'o'),交集有'*'就连边#include #include #include #include #include using namespa... 阅读全文
posted @ 2014-11-02 17:25 LegendaryAC 阅读(503) 评论(2) 推荐(0)
HDU 1054
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1054二分图最少顶点覆盖,模板题,双向边最后结果/2#include #include #include using namespace std ;struct node{ int s,t,nxt ;}e[1... 阅读全文
posted @ 2014-10-30 09:29 LegendaryAC 阅读(142) 评论(0) 推荐(0)
HDU 4185
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4185两个挨着的'#'可以配成一对,求最多能配成几对挨着的'#'就连边,然后求一次最大匹配,答案是最大匹配除以二(因为1 2和2 1这两对匹配实际效果是1,但是会算成2)#include #include #inc... 阅读全文
posted @ 2014-07-18 14:21 LegendaryAC 阅读(224) 评论(0) 推荐(0)
HDU 3829
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2970P个小朋友喜欢猫讨厌狗,喜欢狗讨厌猫,移除一定数量的猫狗,使开心的小朋友数量最多二分图最大独立集=顶点数-二分图最大匹配对喜好冲突的小朋友连边,因为对小朋友建图拆了点,求出的最大匹配要除以2和hdu 1068... 阅读全文
posted @ 2014-06-20 05:44 LegendaryAC 阅读(590) 评论(0) 推荐(0)
FZU 1202
摘要:http://acm.fzu.edu.cn/problem.php?pid=1202二分图最大匹配,问哪些边是必要的,O(n^3)的方法删边的时候把连接关系也要删掉,如果在此基础上无法找到增广路,加入答案,恢复连接关系,如果能找到,连接关系不用恢复(因为要n对匹配,这组匹配新的了剩下的要留给别的组)... 阅读全文
posted @ 2014-06-04 18:35 LegendaryAC 阅读(189) 评论(0) 推荐(0)
HDU 1498
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1498最小顶点覆盖,建立二分图求最大匹配#include #include #include using namespace std ;int M[105][105],k,n,match[505],vis[505]... 阅读全文
posted @ 2014-04-16 21:24 LegendaryAC 阅读(316) 评论(0) 推荐(0)
HDU 1281
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1281同行同列最多只能放一辆车,所以可以看做二分图。把x坐标和y坐标分别看做二分图的两边点集,把二分图的边看做放车,所以放最多的车就是求二分图的最大匹配。从头删边,如果删掉以后的最大匹配小于原最大匹配,该边就构成重... 阅读全文
posted @ 2014-04-16 16:33 LegendaryAC 阅读(410) 评论(0) 推荐(0)
HDU 1068
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1068应用匈牙利算法第三个扩展,求二分图的最大独立集,但由于路径是双向的,所以求出的最大匹配是实际最大匹配数*2,还要再除回去才行,单向路径就没有这个问题#include #include #include usi... 阅读全文
posted @ 2014-04-15 16:18 LegendaryAC 阅读(181) 评论(0) 推荐(0)
HDU 2444
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2444判断是否构成二分图,如果有则求最大匹配二分图判断用染色法,一个dfs就出来,具体看代码#include #include using namespace std ;int n,m ;struct node{ ... 阅读全文
posted @ 2014-04-10 17:37 LegendaryAC 阅读(117) 评论(0) 推荐(0)
匈牙利算法
摘要:二分图最大匹配邻接表:O(nm)struct node{ int s,t,nxt ; }e[1005] ;int k,m,n,head[505],cnt,match[505],vis[505] ;int find(int s){ for(int i=head[s] ;i!=-1 ;i=e... 阅读全文
posted @ 2014-04-09 10:52 LegendaryAC 阅读(278) 评论(0) 推荐(0)
HDU 1150 Machine Schedule
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1150二分图最大匹配,匈牙利算法View Code #include #include const int MAX1=101;const int MAX2=1001;int k,m,n;int match[MAX1... 阅读全文
posted @ 2012-05-21 17:55 LegendaryAC 阅读(143) 评论(0) 推荐(0)
HDU 2063 过山车
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2063二分图最大匹配,参照白书上邻接表建的图View Code #include #include const int MAX1=501;const int MAX2=1001;int k,m,n;int matc... 阅读全文
posted @ 2012-05-20 15:56 LegendaryAC 阅读(121) 评论(0) 推荐(0)