Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我的第50道题呀 发个贴纪念一下坑爹的匈牙利算法#include <iostream> using namespace std; int d[201]; bool v[201],map[201][201]; int n,m,num; bool find(int x) { int i,j; for(i=n;i<n+m;i++) if(map[x][i] && v[i]!=true) { v[i]=true; if(d[i]==-1 || find(d[i])) { d[i]=x; return true; } } return false; } int process() { int ans=0,i; memset( d,-1,sizeof(d) ); for(i=1;i<n;i++) { memset(v,false,sizeof(v)); if(find(i)) ans++; } return ans; } int main() { int i,j; int a,b,c; scanf("%d",&n); while(n!=0) { memset(map,false,sizeof(map)); scanf("%d %d",&m,&num); for(i=0;i<num;i++) { scanf("%d %d %d",&a,&b,&c); if(b&&c) map[b][c+n]=true; } printf("%d\n",process()); scanf("%d",&n); }//while return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator