ACM PKU 1325 Machine Schedule http://poj.org/problem?id=1325

本文详细介绍了如何使用匈牙利算法解决匹配问题,并通过实例展示了算法的实现过程,包括代码演示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一个二分图的题目,匈牙利算法,跟着老师做完了,展示老师的代码,威武,哈哈

 1 #include <iostream>
2 #include <stdio.h>
3 #include <string.h>
4 using namespace std;
5 const int maxn=105;
6
7 bool flag[maxn];
8 int match[maxn];
9 int map[maxn][maxn];
10
11 int N,M,K;
12
13 bool xyy(int s)
14 {
15 for(int i=0; i<M; i++)
16 {
17 if(map[s][i]&&!flag[i])
18 {
19 flag[i]=1;
20 if(match[i]==-1||xyy(match[i]))
21 {
22 match[i]=s;
23 return true;
24 }
25 }
26 }
27 return false;
28 }
29
30 int main()
31 {
32 //freopen("in.txt","r",stdin);
33 while(scanf("%d",&N))
34 {
35 if(N==0) break;
36 scanf("%d%d",&M,&K);
37 int a,x,y;
38 memset(map,0,sizeof(map));
39 memset(match,-1,sizeof(match));
40 for(int i=0; i<K; i++)
41 {
42 scanf("%d%d%d",&a,&x,&y);
43 if(!x||!y) continue;
44 map[x][y]=1;
45 }
46 int cnt=0;
47 for(int i=1;i<=N;i++)
48 {
49 memset(flag,0,sizeof(flag));
50 if(xyy(i))cnt++;
51 }
52 printf("%d\n",cnt);
53 }
54 return 0;
55 }

  

转载于:https://www.cnblogs.com/Chinese-Coder-Clarence/articles/2136632.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值