1 #include<iostream> 2 #include<stdio.h> 3 #define MAXN 105 4 using namespace std; 5 6 int _m[MAXN][MAXN]; 7 int match[MAXN]; 8 bool ck[MAXN]; 9 10 11 bool search(int a,int b,int x) 12 { 13 int i; 14 int t; 15 for ( i = 0 ; i < b ; i++) 16 if (_m[x][i] && ! ck[i]) 17 { 18 ck[i] = true; 19 t = match[i]; 20 match[i] = x; 21 if (t == -1 || search(a,b,t)) 22 return true; 23 match[i] = t; 24 } 25 return false; 26 } 27 28 int hungary(int a,int b) 29 { 30 memset(match,-1,sizeof(match)); 31 int max_match = 0; 32 int i; 33 for ( i = 0 ; i < a ; i++) 34 { 35 memset(ck,false,sizeof(ck)); 36 if (search(a,b,i)) 37 max_match++; 38 } 39 return max_match; 40 } 41 42 43 int main() 44 { 45 //freopen("acm.acm","r",stdin); 46 int num_x; 47 int num_y; 48 int work; 49 int x; 50 int y; 51 int i; 52 int tem; 53 while(cin>>num_x>>num_y>>work) 54 { 55 if(num_x == 0) 56 break; 57 memset(_m,0,sizeof(_m)); 58 for(i = 0; i < work; ++ i) 59 { 60 cin>>tem>>x>>y; 61 if(x*y != 0) 62 { 63 //-- x; 64 //-- y; 65 _m[x][y] = 1; 66 } 67 } 68 cout<<hungary(num_x,num_y)<<endl; 69 } 70 71 }
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。
技术网站地址: vmfor.com