匈牙利算法by Beyond the VoidWord文档格式.docx

上传人:b****5 文档编号:18899469 上传时间:2023-01-02 格式:DOCX 页数:19 大小:990.43KB
下载 相关 举报
匈牙利算法by Beyond the VoidWord文档格式.docx_第1页
第1页 / 共19页
匈牙利算法by Beyond the VoidWord文档格式.docx_第2页
第2页 / 共19页
匈牙利算法by Beyond the VoidWord文档格式.docx_第3页
第3页 / 共19页
匈牙利算法by Beyond the VoidWord文档格式.docx_第4页
第4页 / 共19页
匈牙利算法by Beyond the VoidWord文档格式.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

匈牙利算法by Beyond the VoidWord文档格式.docx

《匈牙利算法by Beyond the VoidWord文档格式.docx》由会员分享,可在线阅读,更多相关《匈牙利算法by Beyond the VoidWord文档格式.docx(19页珍藏版)》请在冰豆网上搜索。

匈牙利算法by Beyond the VoidWord文档格式.docx

while(从邻接表中列举k能关联到顶点j)

{

if(j不在增广路上)

{

把j加入增广路;

if(j是未盖点或者从j的对应项出发有可增广路)

{

修改j的对应项为k;

则从k的对应项出有可增广路,返回true;

}

}

}

则从k的对应项出没有可增广路,返回false;

}

void匈牙利hungary()

fori->

1ton

if(则从i的对应项出有可增广路)

匹配数++;

输出匹配数;

演示

C实现(作者BYVoid)?

CPP

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

#include<

stdio.h>

string.h>

#defineMAX102

longn,n1,match;

longadjl[MAX][MAX];

longmat[MAX];

boolused[MAX];

FILE*fi,*fo;

voidreadfile()

fi=fopen("

flyer.in"

"

r"

);

fo=fopen("

flyer.out"

w"

fscanf(fi,"

%ld%ld"

&

n,&

n1);

longa,b;

while(fscanf(fi,"

a,&

b)!

=EOF)

adjl[a][++adjl[a][0]]=b;

match=0;

boolcrosspath(longk)

for(longi=1;

i<

=adjl[k][0];

i++)

longj=adjl[k][i];

if(!

used[j])

used[j]=true;

if(mat[j]==0||crosspath(mat[j]))

mat[j]=k;

returntrue;

returnfalse;

voidhungary()

=n1;

if(crosspath(i))

match++;

memset(used,0,sizeof(used));

voidprint()

fprintf(fo,"

%ld"

match);

fclose(fi);

fclose(fo);

intmain()

readfile();

hungary();

print();

return0;

Pascal实现(作者魂牛)?

PASCAL

var

a:

array[1..1000,1..1000]ofboolean;

b:

array[1..1000]oflongint;

c:

array[1..1000]ofboolean;

n,k,i,x,y,ans,m:

longint;

functionpath(x:

longint):

boolean;

i:

begin

fori:

=1tondo

ifa[x,i]andnotc[i]then

begin

c[i]:

=true;

if(b[i]=0)orpath(b[i])then

b[i]:

=x;

exit(true);

end;

exit(false);

end;

procedurehungary;

fillchar(b,sizeof(b),0);

=1tomdo

fillchar(c,sizeof(c),0);

ifpath(i)theninc(ans);

fillchar(a,sizeof(a),0);

readln(m,n,k);

=1tokdo

readln(x,y);

a[x,y]:

ans:

=0;

hungary;

writeln(ans);

end.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 人文社科 > 哲学历史

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1