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. ASP.NET MVC进阶之路:深入理解依赖注入(DI)和控制反转(IOC)

    0X1 什么是依赖注入 依赖注入(Dependency Injection),是这样一个过程:某客户类只依赖于服务类的一个接口,而不依赖于具体服务类,所以客户类只定义一个注入点.在程序运行过程中,客户 ...

  2. css为网页顶部和底部都加入背景图

    网页背景图是我们常用的功能,一般来说.给网页加一个背景图,只要在网页的body标签中加入css属性就行. 代码如下:<body style="background-image:url( ...

  3. Android Studio ADB响应失败解决方法

    当启动Android Studio时,如果弹出 adb not responding. you can wait more,or kill "adb.exe" process ma ...

  4. c 输入两个数,第一个数决定一个nXn的矩阵,第二个数决定从1开始赋值,赋值的上限 (MD花了半天时间,思路不对害死人)

    输入两个数,第一个数决定一个nXn的矩阵,第二个数决定从1开始赋值,赋值的上限 比如: 输入: 输出: 输入: 输出: #include<stdio.h> int main(void) { ...

  5. JavaScript 数字相关的转换和方法

    类型判断 isNaN - 是否是 NaN(Not a Number).主要用来判断 NaN 是否是 NaN,因为 NaN == NaN 是 false. isNaN(NaN);       // tr ...

  6. nvarchar and nchar

    Same: 1.store unicode charactor. 2. A charactor is stroed with 2 bytes. Different. 1. nchar  会自动填充数据 ...

  7. SQL 注入与防御实例

    注入 1. 创建存储 USE TSQL2012; GO IF OBJECT_ID('Sales.ListCustomersByAddress') IS NOT NULL DROP PROCEDURE ...

  8. linker command failed with exit code 1 (use -v to see invocation),经典Xcode编译错误的出现和解决!

    linker command failed with exit code 1 (use -v to see invocation)这个肯定是个xcode编译运行的时候经典的报错了. 这个问题曾经在我的 ...

  9. Java之JDOM生成XML和解析

    一.生成XML文件 1.JDOM是对Java原始的类进行了封装.让解析XML文件变得很方便 2.创建一个XML文件的根节点: Element root = new Element("HD&q ...

  10. Object lifetime

    Object lifetime Temporary object lifetime Storage reuse Access outside of lifetime Every object has ...