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的更多相关文章

  1. ST算法 Sliding Window algorithm template

    ST算法(Sliding Window):A easy way to slove the substring problems algorithm template to slove substrin ...

  2. [Algorithm] Maximum Flow

    Ref MIT: lecture-13-incremental-improvement-max-flow-min-cut/ Ford Fulkerson algorithm for finding m ...

  3. STL algorithm源代码:stl_algo.h

    <span style="font-size:18px;">// Algorithm implementation -*- C++ -*- // Copyright ( ...

  4. STL sort 函数实现详解

    作者:fengcc 原创作品 转载请注明出处 前几天阿里电话一面,被问到STL中sort函数的实现.以前没有仔细探究过,听人说是快速排序,于是回答说用快速排序实现的,但听电话另一端面试官的声音,感觉不 ...

  5. GMM的EM算法实现

    转自:http://blog.csdn.net/abcjennifer/article/details/8198352 在聚类算法K-Means, K-Medoids, GMM, Spectral c ...

  6. I am Nexus Master!(虽然只是个模拟题。。。但仍想了很久!)

    I am Nexus Master!  The 13th Zhejiang University Programming Contest 参见:http://www.bnuoj.com/bnuoj/p ...

  7. UESTC 1852 Traveling Cellsperson

    找规律水题... Traveling Cellsperson Time Limit: 1000ms Memory Limit: 65535KB This problem will be judged ...

  8. UESTC 1851 Kings on a Chessboard

    状压DP... Kings on a Chessboard Time Limit: 10000ms Memory Limit: 65535KB This problem will be judged ...

  9. Vector_h

    #ifndef VECTOR_H #define VECTOR_H #include <algorithm> template<typename Object> class V ...

随机推荐

  1. bzoj 1047 : [HAOI2007]理想的正方形 单调队列dp

    题目链接 1047: [HAOI2007]理想的正方形 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2369  Solved: 1266[Submi ...

  2. cocos2dx 随机函数

    cocos2dx 随机数  2.2.3版本 1.初始化时设定随机数种子,只需一次. time_t now = time(NULL); srand((unsigned int)now); 2.需要的时候 ...

  3. 射频识别技术漫谈(26)——Felica的文件系统

    Felica的文件系统使用“系统\域\服务\数据块”的结构,如下图所示.通过这种结构实现对卡片非易失性存储区的使用和操作.                                     Fe ...

  4. ThreadSafeClientConnManager用来支持多线程的使用http client

    import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.clien ...

  5. php如何在原来的时间上加一天?一小时

    php如何在原来的时间上加一天?一小时? <?phpecho "今天:",date('Y-m-d H:i:s'),"<br>";echo &q ...

  6. [C++ Basic]C++与Java的主要区别

    1.编译运行 java是解释性语言,java程序在运行时类加载器从类路经中加载相关的类,然后java虚拟机读取该类文件的字节,执行相应操作.而C++编译的 时候将程序编译成本地机器码.一般来说java ...

  7. 笔试题:金额转换,阿拉伯数字的金额转换成中国传统的形式如:(¥1011)->(一千零一拾一元整)输出

    收集这道题目原因是以前做过,但是实现的很麻烦,这次看到别人写的感觉简单易懂. 从一个pdf看到,出处就不贴了 = .= public class RenMingBi { private static ...

  8. Visual Studio warning MSB3270:There was a mismatch between the processor architecture of the project being built "MSIL"

    Problem: There was a mismatch between the processor architecture of the project being built "MS ...

  9. java反射机制入门3

    Method对象的机制与实现 1.Method对象概述 1)java.lang.reflect.Method类是用于表示类中.接口中方法对象的类. 2)可以操作类中私有,以及公有等全部方法. 2.Me ...

  10. 「OC」类和对象

    一.面向对象 OC语言是面向对象的,c语言是面向过程的,面向对象和面向过程只是解决问题的两种思考方式,面向过程关注的是解决问题涉及的步骤,面向对象关注的是设计能够实现解决问题所需功能的类. 术语:OO ...