![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
图论-二分匹配
文章平均质量分 64
___Evan
这个作者很懒,什么都没留下…
展开
-
HDU-1045 Hopcroft-Karp算法
/* 模型转换: 将每行被墙隔开的连续区域称为‘块’ 把横向块看做二分图的顶点集合X 竖向块看做集合Y 横向块和竖向块有冲突就在他们之间连边 */ #include "stdio.h" #include "string.h" #include "queue" using namespace std; const int inf = 1<<30; const int maxn = 15; in原创 2013-11-03 14:03:17 · 683 阅读 · 0 评论 -
POJ1486 Sorting Slides 二分图最大匹配 必要匹配
http://poj.org/problem?id=1486 题意:读题读得很纠结~~ 大意就是平面坐标上有一系列的矩形(各边都和坐标轴平行)和 一些点;每个矩形和在他之内的点对应; 然后找出那些绝对匹配(就是在任何最大匹配中,某个矩形和某个点始终对应); 所谓必要匹配在本题中的意思就是,在所有的最大匹配中,1个数字都会匹配到同一个字母上去。数字x只能原创 2013-12-02 10:09:39 · 592 阅读 · 0 评论 -
Poj-2446 Chessboard 二分匹配
#include #include #include #include #include using namespace std; typedef long long LL; const int maxn = 105; const int M = 50*50; const int Mod = 1000000007; int n,m,K; int nx,ny; int id[maxn][m原创 2014-07-14 14:42:44 · 379 阅读 · 0 评论 -
hdu 2119 Matrix 二分图 最小点覆盖
题目链接原创 2014-07-17 19:59:38 · 370 阅读 · 0 评论 -
hdu 2389 Rain on your Parade 二分匹配 HK算法
题目链接 匈牙利算法原创 2014-07-17 20:43:03 · 396 阅读 · 0 评论 -
Poj-2060 Taxi Cab Scheme 二分图最小路径覆盖
#include #include #include #include #include using namespace std; typedef long long LL; const int maxn = 505; const int Mod = 1000000007; const double inf = 1<<30; int n; int map[maxn][maxn]; str原创 2014-07-18 13:16:25 · 416 阅读 · 0 评论 -
hdu-2819 Swap 二分图匹配
#include #include #include #include #include using namespace std; typedef long long LL; const int maxn = 505; const int Mod = 1000000007; const double inf = 1<<30; int n,m; int map[maxn][maxn]; i原创 2014-07-18 15:05:11 · 391 阅读 · 0 评论 -
Poj-2289 Jamie's Contact Groups 多重二分图匹配
#include #include #include #include #include #include using namespace std; typedef long long LL; const int maxn = 1005; const int Maxn = 505; const int Mod = 1000000007; const double inf = 1<<30原创 2014-07-18 20:02:28 · 513 阅读 · 0 评论 -
Toj 3345/hdu 1281 Chinese Chess 二分图匹配
#include "stdio.h" #include "string.h" #include "queue" #include "vector" #include "algorithm" using namespace std; const int maxn = 10005; const int inf = 1<<30; int n,m,k,st,ed; vectormap[maxn],map1原创 2014-07-18 23:22:46 · 440 阅读 · 0 评论 -
HDU-2255 奔小康赚大钱 裸KM
#include #include #include using namespace std; const int maxn = 305; const int inf = 1<<30; int nx,ny; int map[maxn][maxn]; //邻接矩阵 int cx[maxn],cy[maxn]; //保存匹配上的集合 bool visx[maxn],visy[maxn转载 2013-11-03 14:04:36 · 680 阅读 · 0 评论 -
HDU-1533 KM Going Home 最佳匹配 最小费用最大流
/* 题目大意: 给你一个N行M列的矩阵,其中“.”代表空地,“H”代表房子,“m”代表人,其中有n个房子和n个人。现在要求每个人进入一间房子,且人走一步需要支付1美元。 求最小需要花费多少美元才能让所有人都进入到房子中(每个人只能进入一间房子,每个房子只能容纳一个人)。 解题思路: 这道题其实就是二分图最优匹配的变形而已。 因为要求的其实是最小权值之和。而KM算法求的是最大权值之和。 为此,我原创 2013-11-03 14:04:08 · 715 阅读 · 0 评论 -
HDU-2389 Rain on your Parade 裸Hopcroft–Karp algorithm
#include "stdio.h" #include "string.h" #include "queue" const int maxn = 3005; const int inf = 1<<30; int nx,ny,time; //左集合顶点数 右集合顶点数 int dis; int map[maxn][maxn]; //二分原创 2013-11-03 14:00:10 · 609 阅读 · 0 评论 -
HDU-1150 HK二分图最小点覆盖
//二分图最小点覆盖 = 二分图最大匹配 #include #include #include using namespace std; const int maxn = 105; const int inf = 1<<30; int nx,ny,m; int dis; int map[maxn][maxn]; int cx[maxn],cy[maxn]; int dx[maxn],dy[max原创 2013-11-03 13:59:37 · 613 阅读 · 0 评论 -
HDU-2458 Kindergarten 最大完全子图(最大团)中顶点的个数
/* 本题是要求图中的最大完全子图(最大团)中顶点的个数。由于原图的补图是一个二分图,其最大完全数等价于其补图的最大独立集中元素的个数,于是可以根据二分图的性质求出这个最大独立集。而普通图的最大团则是一个NP问题。 定理:二分图最大独立集中元素个数=顶点数-二分图最大匹配数 最大完全数:图中最大完全子图的顶点个数。 独立集:图中任意两个顶点都不相原创 2013-11-03 14:00:48 · 1949 阅读 · 0 评论 -
Hopcroft-Karp算法 二分图最小路径覆盖
//二分图最小路径覆盖 = 顶点数 - 最大匹配 #include #include #include using namespace std; const int maxn = 105; const int inf = 1<<30; int nx,ny,m; int dis; int map[maxn][maxn]; int cx[maxn],cy[maxn]; int dx[maxn],dy[原创 2013-11-03 14:01:29 · 729 阅读 · 0 评论 -
HDU-4160 Doll 最小路径覆盖
/* 题意:给出n个箱子,箱子可以放在箱子里边,但是要满足放在里边的箱子的长要小于外边的长,宽要满足小于外边的宽,高要满足小于外边的高。求露在外边的箱子最多有多少个。 思路:思路:最小路径覆盖,如果满足条件:wi j连边,然后就是求最大匹配。 最小路径覆盖=顶点数-最大匹配。 */ #include "stdio.h" #include "string.h" #include "queue"原创 2013-11-03 14:02:05 · 615 阅读 · 0 评论 -
HDU-4160 Doll 匈牙利算法
/* 题意:给出n个箱子,箱子可以放在箱子里边,但是要满足放在里边的箱子的长要小于外边的长,宽要满足小于外边的宽,高要满足小于外边的高。求露在外边的箱子最多有多少个。 思路:思路:最小路径覆盖,如果满足条件:wi j连边,然后就是求最大匹配。 最小路径覆盖=顶点数-最大匹配。 */ #include "stdio.h" #include "string.h" #include "algorit原创 2013-11-03 14:02:36 · 609 阅读 · 0 评论 -
KM算法 - 大牛模板
/* http://blog.sina.com.cn/s/blog_7b7c7c5f01011sgw.html [KM算法的几种转化] KM算法是求最大权完备匹配,如果要求最小权完备匹配怎么办?方法很简单,只需将所有的边权值取其相反数,求最大权完备匹配,匹配的值再取相反数即可。 KM算法的运行要求是必须存在一个完备匹配,如果求一个最大权匹配(不一定完备)该如何办?依然很简单,把不存在的边权值赋为0原创 2013-11-03 14:05:32 · 664 阅读 · 0 评论 -
判断是否为二分图 染色法
#include #include #include #include using namespace std; const int maxn = 105; int color[maxn]; vectorG[maxn]; bool bipartite( int u ) //起点 { for( int i = 0; i < G[u].size(); i ++ ) { int v = G[u原创 2013-11-03 14:06:06 · 638 阅读 · 0 评论 -
FAFU-1198 小三大作战 多重匹配
#include "stdio.h" #include "string.h" const int maxn = 105; int map[maxn][maxn],cap[maxn],data[maxn][maxn],flow[maxn];; int n,m; bool vis[maxn]; bool dfs(int x) { for( int i=1; i<=m; i++ ) //遍历每个GG原创 2013-11-03 13:59:02 · 568 阅读 · 0 评论 -
hdu 2444 The Accomodation of Students 二分图判断 + 最大匹配
#include #include #include #include #include using namespace std; typedef long long LL; const int maxn = 205; const int Mod = 1000000007; int n,m; bool vis[maxn]; int cx[maxn],cy[maxn]; int map[m原创 2014-07-17 20:03:16 · 362 阅读 · 0 评论