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. 透过byte数组简单分析Java序列化、Kryo、ProtoBuf序列化

    序列化在高性能网络编程.分布式系统开发中是举足轻重的之前有用过Java序列化.ProtocolBuffer等,在这篇文章这里中简单分析序列化后的byte数组观察各种序列化的差异与性能,这里主要分析Ja ...

  2. Linux信号类型说明

    说明 在Linux系统开发中经常要使用到信号来实现异步通知机制.而在Linux系统中信号有很多种,也不用全部记住,学习几种常见的信号,学会使用即可:当然也要知道用哪种方式能够发送这样的信号. 查看li ...

  3. gdb 定位 oops call trace

    [    1.454380] BUG: unable to handle kernel NULL pointer dereference at 00000000000005d0[    1.47402 ...

  4. C语言数据库编程

    ----摘自个人C语言数据库项目报告 3.4逻辑结构的SQL语句实现 创建基本表: 3.4-1建立商品表: create table goods(goods_id int primary key,go ...

  5. Linux Gitlab

    一.简介 GitLab是利用 Ruby on Rails 一个开源的版本管理系统,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目.它拥有与Github类似的功能,能够浏览源 ...

  6. C# .NET 动态调用webservice的三种方式

    转载自 百度文库 http://wenku.baidu.com/link?url=Q2q50wohf5W6UX44zqotXFEe_XOMaib4UtI3BigaNwipOHKNETloMF4ax4W ...

  7. [转]Ionic系列——CodePen上的优秀Ionic_Demo

    本文转自:http://my.oschina.net/u/1416844/blog/514361?fromerr=bbFC5JIl 案例网站 Slidebox with Dynamic Slides ...

  8. I am back-电商网站开发&jQuery

    hi 之前有将近两周的时间没有更新,除了懒就是其他的事情耽误了.现在好了,回家了,虽然家里停水,外面又有积雪,天寒地冻的,但诸多不便,都比不过有点闲的好. 开搞每个学PHP的必经之路——电商网站的开发 ...

  9. NOIP2010引水入城[BFS DFS 贪心]

    题目描述 在一个遥远的国度,一侧是风景秀美的湖泊,另一侧则是漫无边际的沙漠.该国的行政区划十分特殊,刚好构成一个N 行M 列的矩形,如上图所示,其中每个格子都代表一座城市,每座城市都有一个海拔高度. ...

  10. Object.Destroy慎用

    Object.Destory Destory(Object)并没有立刻,马上,及时的删除这个Object. 举例 在使用NGUI的Table或Grid进行布局时,就需要注意了:尽量不要使用Destro ...