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 ...
随机推荐
- LintCode-两数之和
题目描述: 给一个整数数组,找到两个数使得他们的和等于一个给定的数target. 你需要实现的函数twoSum需要返回这两个数的下标, 并且第一个下标小于第二个下标.注意这里下标的范围是1到n,不是以 ...
- VARCHAR2(N CHAR)与VARCHAR2(N)的区别[Oracle基础]
转载: http://blog.itpub.net/24930246/viewspace-1064982 在数据库开发的时候,经常需要考虑存储空间的问题,当然很多时候我们并不需要去考虑一些细小的差别, ...
- 飘逸的python - 一个最简单的服务器
python拥有这种单独起一个服务器监听端口的能力,用标准库的wsgiref就行. from wsgiref.simple_server import make_server def simple_a ...
- MessageDigest简单介绍
本文博客原文 參考文章:http://blog.sina.com.cn/s/blog_4f36423201000c1e.html 一.概述 java.security.MessageDigest类用于 ...
- 创建BDC(Business Data Connectivity Service)
创建Business Data Connectivity http://blog.csdn.net/spfarm/article/details/44015915 创建和使用Business Data ...
- Informatica 9.5.1 安装配置
Informatica 结构 1个或多个资源库(Respository) PowerCenter数据整合引擎是基于元数据驱动的,提供了基于数据驱动的元数据知识库(Repository),该元数据知识 ...
- tomcat部署web项目的三种方式
方式一:将web项目拷贝至webapps目录下. 方式二:修改tomcat目录下的conf目录下的server.xml,在其<Host>标签中添加子标签,代码如下: <Host ap ...
- js 精美倒计时
精美倒计时*{ padding:0; margin:0;}.colockbox{width:250px;height:30px;background:url(/jscss/demoimg/201312 ...
- shell 脚本中$$,$#,$?分别代表什么意思?
$0 这个程式的执行名字$n 这个程式的第n个参数值,n=1..9$* 这个程式的所有参数,此选项参数可超过9个.$# 这个程式的参数个数$$ 这个程式的PID(脚本运行的当前进程ID号)$! 执行上 ...
- python笔记之字符串
列表,元组,字符串的相互转换: 将字符串转换为序列和元组: >>> s="hello" >>> list(s)['h', 'e', 'l', ' ...