1 #include<iostream> 2 #include<algorithm> 3 #define MAXN 305 4 using namespace std; 5 6 int _m[MAXN][MAXN]; 7 int time[8][15]; 8 int match[MAXN]; 9 bool ck[MAXN]; 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 int main() 43 { 44 //freopen("acm.acm","r",stdin); 45 int n; 46 int num; 47 int i; 48 int j; 49 int u; 50 int v; 51 int k; 52 int node_num = 0; 53 while(cin>>n) 54 { 55 node_num = 0; 56 memset(_m,0,sizeof(_m) ); 57 memset(time,-1,sizeof(time)); 58 for(k = 0; k < n; ++ k) 59 { 60 cin>>num; 61 for(i = 0; i < num; ++ i) 62 { 63 cin>>u>>v; 64 -- u; 65 -- v; 66 if(time[u][v] == -1) 67 { 68 time[u][v] = node_num ++; 69 _m[k][time[u][v]] = 1; 70 } 71 else 72 { 73 _m[k][time[u][v]] = 1; 74 } 75 } 76 } 77 cout<<hungary(n,node_num)<<endl; 78 } 79 80 }
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。
技术网站地址: vmfor.com