The Hungarian algorithm Template
The Hungarian algorithm with The adjacency matrix :
计算最大匹配问题
int n1, n2, m, ans;
int res[MAXN];
bool vis[MAXN], map[MAXN][MAXN]; void init(){
int t1, t2;
memset(map, , sizeof(map));
memset(res, , sizeof(res));
ans = ;
scanf("%d%d",&n1,&n2); //get map[][] }
bool find(int a) {
for (int i = ; i <= n2; ++i) {
if (map[a][i] == && !vis[i]) {
vis[i] = true;
if (res[i] == || find(res[i])) {
res[i] = a;
return true;
}
}
}
return false;
}
int main() {
init();
for (int i = ; i <= n1; ++i) {
memset(vis, , sizeof(vis));
if (find(i)) ++ans;
}
printf("%d\n",ans);
return ;
}
The Hungarian algorithm Template的更多相关文章
- ST算法 Sliding Window algorithm template
ST算法(Sliding Window):A easy way to slove the substring problems algorithm template to slove substrin ...
- [Algorithm] Maximum Flow
Ref MIT: lecture-13-incremental-improvement-max-flow-min-cut/ Ford Fulkerson algorithm for finding m ...
- STL algorithm源代码:stl_algo.h
<span style="font-size:18px;">// Algorithm implementation -*- C++ -*- // Copyright ( ...
- STL sort 函数实现详解
作者:fengcc 原创作品 转载请注明出处 前几天阿里电话一面,被问到STL中sort函数的实现.以前没有仔细探究过,听人说是快速排序,于是回答说用快速排序实现的,但听电话另一端面试官的声音,感觉不 ...
- GMM的EM算法实现
转自:http://blog.csdn.net/abcjennifer/article/details/8198352 在聚类算法K-Means, K-Medoids, GMM, Spectral c ...
- I am Nexus Master!(虽然只是个模拟题。。。但仍想了很久!)
I am Nexus Master! The 13th Zhejiang University Programming Contest 参见:http://www.bnuoj.com/bnuoj/p ...
- UESTC 1852 Traveling Cellsperson
找规律水题... Traveling Cellsperson Time Limit: 1000ms Memory Limit: 65535KB This problem will be judged ...
- UESTC 1851 Kings on a Chessboard
状压DP... Kings on a Chessboard Time Limit: 10000ms Memory Limit: 65535KB This problem will be judged ...
- Vector_h
#ifndef VECTOR_H #define VECTOR_H #include <algorithm> template<typename Object> class V ...
随机推荐
- 转: 深入理解 AngularJS 的 Scope
查看 DEMO.参考 StackOverflow. ng-switch ng-switch 的原型继承和 ng-include 一样.所以如果你需要对基本类型数据进行双向绑定,使用 $parent ...
- word-break与word-wrap
本文列举了兼容 IE 和 FF 的换行 CSS 推荐样式,详细介绍了word-wrap同word-break的区别. 兼容 IE 和 FF 的换行 CSS 推荐样式 最好的方式是 以下是引用片段: ...
- Oracle DBA常用的系统表
1.2 DBA常用的表1.2.1 dba_开头 dba_users数据库用户信息 dba_segments 表段信息 dba_extents 数据区信息 dba_ob ...
- HDOJ Sudoku Killer(dfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1426 思路分析:该问题为数独问题,明显解是唯一的,所有采用dfs搜索效果更好: 在搜索时,可以通过3个 ...
- installation - How to install Synaptic Package Manager? - Ask Ubuntu
installation - How to install Synaptic Package Manager? - Ask Ubuntu How to install Synaptic Package ...
- Android开发小记
一,下载解压adt-bundle,直接可以用来开发了二,新建android项目时不勾选创建activity,来看看如何手动创建activity1,在空项目添加class文件,选择超类为activity ...
- 讲讲金融业务(一)--自助结算终端POS
之前在群里和大家聊天的时候,发现好多人对银行业务比較感兴趣,或许是由于大家对银行不了解,以为非常神奇的样子.全部,从这周開始我打算把我肚子里的墨水慢慢地倒出来,和大家分享分享. 在技术还不发达的时 ...
- hql中不能写count(1)能够写count(a.id)
hql中不能写count(1)能够写count(a.id)里面写详细的属性 String hql="select new com.haiyisoft.vo.entity.cc.repo.Bu ...
- 2014多校3 Wow! Such Sequence!段树
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=4893 这个问题还真是纠结啊--好久不写线段树的题了.由于这几天学伸展树.然后认为线段树小case了. ...
- python切片练习
这块儿没什么难的,细心一点就好 L = [] n = 1 while n <= 99: L.append(n) n = n + 2 print(L) #但是在Python中,代码不是越多越好,而 ...