type node=^link;
link=record
des:longint;
next:node;
end; var
n,m,i,t,num:longint;
p:node;
nd:array[..] of node;
mat:array[..] of longint;
vis:array[..] of boolean;
sel:array[..] of longint; function find(po:longint):boolean;
var
p:node;
begin
p:=nd[po];
while p<>nil do
begin
if vis[p^.des]=false then
begin
vis[p^.des]:=true;
if sel[p^.des]= then
begin
sel[p^.des]:=po;
mat[po]:=p^.des;
exit(true);
end else
if find(sel[p^.des])=true then
begin
sel[p^.des]:=po;
mat[po]:=p^.des;
exit(true);
end;
end;
p:=p^.next;
end;
exit(false);
end; begin read(n,m); for i:= to n do
begin
read(t);
while t<> do
begin
new(p);p^.next:=nd[t];p^.des:=i;nd[t]:=p;
read(t);
end;
end; for i:= to m do
if mat[i]= then
begin
fillchar(vis,sizeof(vis),);
if find(i) then inc(num);
end; writeln(num); end.

c++

-------------------------------------------------------------------------------------------

BZOJ1059

#include <cstdio>

  int nd[],next[],bt[],des[],sel[],mat[],n,cnt;

  int dfs(int po){
for (int p=nd[po];p!=-;p=next[p])
if (bt[des[p]]==){
bt[des[p]]=;
if (sel[des[p]]==-||dfs(sel[des[p]])){
sel[des[p]]=po;
mat[po]=des[p];
return();
}
}
return();
} int Hung(){
for (int i=;i<=n;i++) sel[i]=-; for (int i=;i<=n;i++){
for (int j=;j<=n;j++) bt[j]=;
if (!dfs(i)) return();
} return();
} void addedge(int x,int y){
next[++cnt]=nd[x];des[cnt]=y;nd[x]=cnt;
} int main(){
int T;
scanf("%d",&T);
while (T--){
cnt=;
scanf("%d",&n); for (int i=;i<=n;i++) nd[i]=-;
for (int i=;i<=n;i++)
for (int j=;j<=n;j++){
int t;
scanf("%d",&t);
if (t) addedge(i,j);
} if (Hung()) printf("Yes\n");else printf("No\n");
}
}

另外,

最小点覆盖数=最大匹配数 
最大独立集=顶点数-最大匹配数
最小路径覆盖数 = 顶点数 - 最大匹配数

_____________________________________________

BZOJ1443

确定一个点是否为匹配的必选点,后手走匹配边

(确定必选边BZOJ2140)

#include <cstdio>
#include <map>
using namespace std; map <int,int> mp; const int dir[][]={{-,},{,-},{,},{,}}; int n,m,b[][],ndx[],ndy[],next[],des[];
int vis[],sel[],mat[],dfstim,xcnt,ycnt,cnt,ans[][];
char st[]; void addedgex(int x,int y){
next[++cnt]=ndx[x];des[cnt]=y;ndx[x]=cnt;
} void addedgey(int x,int y){
next[++cnt]=ndy[x];des[cnt]=y;ndy[x]=cnt;
} int ok(int x,int y){
return(x&&y&&x<=n&&y<=m&&b[x][y]);
} int dfs(int po){
for (int p=ndx[po];p!=-;p=next[p])
if (!vis[des[p]]){
vis[des[p]]=;
if (sel[des[p]]==||dfs(sel[des[p]])){
mat[po]=des[p];sel[des[p]]=po;
return();
}
}
return();
} int checkx(int po){
vis[po]=dfstim;
if (!mat[po]) return();
for (int p=ndy[mat[po]];p!=-;p=next[p])
if (vis[des[p]]<dfstim)
if (checkx(des[p])) return();
return();
} int checky(int po){
vis[po]=dfstim;
if (!sel[po]) return();
for (int p=ndx[sel[po]];p!=-;p=next[p])
if (vis[des[p]]<dfstim)
if (checky(des[p])) return();
return();
} int main(){
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++){
scanf("%s",&st);
for (int j=;j<=m;j++)
if (st[j-]=='.'){
b[i][j]=;
if (((i+j)&)==){
mp[i*+j]=++xcnt;
}else{
mp[i*+j]=++ycnt;
}
}
} for (int i=;i<=xcnt;i++) ndx[i]=-;
for (int i=;i<=ycnt;i++) ndy[i]=-;
for (int i=;i<=n;i++) for (int j=;j<=m;j++)
if (b[i][j]&&(((i+j)&)==))
for (int k=;k<;k++)
if (ok(i+dir[k][],j+dir[k][]))
addedgex(mp[i*+j],mp[(i+dir[k][])*+j+dir[k][]]),
addedgey(mp[(i+dir[k][])*+j+dir[k][]],mp[i*+j]); for (int i=;i<=xcnt;i++){
for (int j=;j<=ycnt;j++) vis[j]=;
dfs(i);
} cnt=;dfstim=;
for (int i=;i<=n;i++) for (int j=;j<=m;j++)
if (b[i][j]){
dfstim++;
int po=mp[i*+j];
if (((i+j)&)==){
if (checkx(po)){
cnt++;
ans[cnt][]=i;ans[cnt][]=j;
}
}else
if (checky(po)){
cnt++;
ans[cnt][]=i;ans[cnt][]=j;
}
} if (cnt) printf("WIN\n");else printf("LOSE\n");
for (int i=;i<=cnt;i++)
printf("%d %d\n",ans[i][],ans[i][]);
}

——————————————————————————————

霍尔定理

二部图G中的两部分顶点组成的集合分别为X, Y, X={X1, X2, X3,X4, .........,Xm} , Y={y1, y2, y3, y4 , .........,yn},G中有一组无公共点的边,一端恰好为组成X的点的充分必要条件是: X中的任意k个点至少与Y中的k个点相邻。

TCO15 Round 1A Revmatching

You have a weighted bipartite graph. Each partition contains n vertices numbered 0 through n-1. You are given the weights of all edges encoded into a vector <string> A with n elements, each containing n characters. For each i and j, A[i][j] is '0' if there is no edge between vertex i in the first partition and vertex j in the second partition. Otherwise, A[i][j] is between '1' and '9', inclusive, and the digit represents the weight of the corresponding edge.

A perfect matching is a permutation p of 0 through n-1 such that for each i there is an edge (of any positive weight) between vertex i in the first partition and vertex p[i] in the second partition.

Your goal is to have a graph that does not contain any perfect matching. You are allowed to delete edges from your current graph. You do not care about the number of edges you delete, only about their weights. More precisely, you want to reach your goal by deleting a subset of edges with the smallest possible total weight. Compute and return the total weight of deleted edges in an optimal solution.

枚举每个X的子集,设其包含k个元素。断开若干点后使得Y中仅有k-1个元素。将断开点的价值求出后排序即可

    int smallest(vector <string> A){
int n=A.size(); int ans=1e9;
for (int i=;i<<<n;i++){
for (int j=;j<=n;j++) sum[j]=;
for (int j=;j<=n;j++)
if (i&(<<(j-)))
for (int k=;k<=n;k++)
sum[k]+=A[j-][k-]-'';
sort(sum+,sum+n+);
int t=bitcount(i),tsum=;
for (int j=;j<=n-t+;j++) tsum+=sum[j];
ans=min(ans,tsum);
}
return(ans);
}

匈牙利算法(codevs2776)的更多相关文章

  1. ACM/ICPC 之 机器调度-匈牙利算法解最小点覆盖集(DFS)(POJ1325)

    //匈牙利算法-DFS //求最小点覆盖集 == 求最大匹配 //Time:0Ms Memory:208K #include<iostream> #include<cstring&g ...

  2. 匈牙利算法——S.B.S.

    匈牙利算法是由匈牙利数学家Edmonds于1965年提出,因而得名.匈牙利算法是基于Hall定理中充分性证明的思想,它是部图匹配最常见的算法,该算法的核心就是寻找增广路径,它是一种用增广路径求二分图最 ...

  3. 匈牙利算法与KM算法

    匈牙利算法 var i,j,k,l,n,m,v,mm,ans:longint; a:..,..]of longint; p,f:..]of longint; function xyl(x,y:long ...

  4. HDU1054 Strategic Game——匈牙利算法

    Strategic Game Bob enjoys playing computer games, especially strategic games, but sometimes he canno ...

  5. poj1274(匈牙利算法)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22809   Accepted: 101 ...

  6. 匈牙利 算法&模板

    匈牙利 算法 一. 算法简介 匈牙利算法是由匈牙利数学家Edmonds于1965年提出.该算法的核心就是寻找增广路径,它是一种用增广路径求二分图最大匹配的算法. 二分图的定义: 设G=(V,E)是一个 ...

  7. 【入门】匈牙利算法+HNOI2006 hero超级英雄

    一.关于匈牙利算法 匈牙利算法是由匈牙利数学家Edmonds提出的,用增广路径求二分图最大匹配的算法. 听起来高端,其实说白了就是: 假设不存在单相思(单身狗偷偷抹眼泪),在一个同性恋不合法的国家里( ...

  8. [ACM_图论] The Perfect Stall 完美的牛栏(匈牙利算法、最大二分匹配)

    描述 农夫约翰上个星期刚刚建好了他的新牛棚,他使用了最新的挤奶技术.不幸的是,由于工程问题,每个牛栏都不一样.第一个星期,农夫约翰随便地让奶牛们进入牛栏,但是问题很快地显露出来:每头奶牛都只愿意在她们 ...

  9. UESTC 919 SOUND OF DESTINY --二分图最大匹配+匈牙利算法

    二分图最大匹配的匈牙利算法模板题. 由题目易知,需求二分图的最大匹配数,采取匈牙利算法,并采用邻接表来存储边,用邻接矩阵会超时,因为邻接表复杂度O(nm),而邻接矩阵最坏情况下复杂度可达O(n^3). ...

  10. Poj(1466),最大独立集,匈牙利算法

    题目链接:http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total S ...

随机推荐

  1. HBase应用开发回顾与总结系列之一:概述HBase设计规范

      概述 笔者本人接触研究HBase也有半年之久了,虽说不上深入和系统,但至少算是比较沉迷.作为部门里大数据技术的探路者,笔者还要承担起技术传播的职责,所以在摸索研究的过程中总是不断地进行总结和测试, ...

  2. oracle存储过程--导出数据库表的说明文档

    Oracle查询表的名字和comments select a.table_name,b.comments from user_tables a,ALL_TAB_COMMENTS b where a.t ...

  3. LeetCode #303. Range Sum Query

    问题: Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclu ...

  4. HADOOP HDFS的设计

    Hadoop提供的对其HDFS上的数据的处理方式,有以下几种, 1 批处理,mapreduce 2 实时处理:apache storm, spark streaming , ibm streams 3 ...

  5. 用FineReport报表系统构建资金监管平台

    一.应用背景 计算机的应用已经渗透到日常工作的许多方面,无论是其自身还是所发挥的作用,计算机都标志着一种高科技,使工作高效率和高水平.为了能更方便,更轻松,更好的管理,信息化建设正在日益发展壮大,更加 ...

  6. 结对编程项目——四则运算vs版

    结对编程项目--四则运算vs版 1)小伙伴信息:        学号:130201238 赵莹        博客地址:点我进入 小伙伴的博客 2)实现的功能: 实现带有用户界面的四则运算:将原只能在 ...

  7. 分布式系统理论之Quorum机制

    一,Quorum机制介绍 在分布式系统中有个CAP理论,对于P(分区容忍性)而言,是实际存在 从而无法避免的.因为,分布系统中的处理不是在本机,而是网络中的许多机器相互通信,故网络分区.网络通信故障问 ...

  8. 详细说说 Google Test Certified 的各级——Level 1

    转载请联系作者,谢谢! 当你作为初创企业或项目的唯一测试人员,一个人一杠枪,你如何开始测试的工作?你是作为一条孤狼,面对10个甚至更多的开发,努力的做一条龙服务(加班加到死):还是想从1到11的转变? ...

  9. poj3635Full Tank?[分层图最短路]

    Full Tank? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7248   Accepted: 2338 Descri ...

  10. java代码封装与编译

    代码封装: 在这个java程序内调用另一个类 在arrayTool中把这两个函数封装起来. 编译顺序:(由下文可知应该是先进行语法检查再进行编译) 先编译ArrayTool再编译ArrayOperat ...