Machine Schedule

二分图匹配求最小点覆盖,注意只要与0连接的都不算(初始状态,不须重启)

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cmath>
 6 using namespace std;
 7 const int maxn=1007;
 8 int n,m,k,ans;
 9 int usd[maxn],ret[maxn];
10 bool map[maxn][maxn];
11 void pre(){
12   memset(usd,false,sizeof(usd));
13   memset(map,false,sizeof(map));
14   memset(ret,-1,sizeof(ret));
15   ans=0;
16 }
17 bool dfs(int x){
18   for(int i=0;i<m;i++){
19     if(!usd[i]&&map[x][i]){
20       usd[i]=true;
21       if(ret[i]==-1||dfs(ret[i])){
22         ret[i]=x;
23         return true;
24       }
25     }
26   }
27   return false;
28 }
29 int main(){
30   while(cin>>n&&n!=0){
31       pre();
32     cin>>m>>k;
33     for(int i=0;i<k;i++){
34       int a,b,c;cin>>c>>a>>b;
35       if(a==0&&b==0) continue;
36       map[a][b]=true;
37     }
38     for(int i=0;i<n;i++){
39       memset(usd,false,sizeof(usd));
40       if(dfs(i)) ans++;
41     }
42     cout<<ans<<endl;
43   }
44   return 0;
45 } 

 

转载于:https://www.cnblogs.com/lcan/p/9792702.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值