标签:des style blog http color java os io
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7577 Accepted Submission(s): 3472
1 #include<cstring> 2 #include<cstdio> 3 #include<cstdlib> 4 using namespace std; 5 const int maxn=1005; 6 int n,a,b,c; 7 bool mat[maxn][maxn]; 8 bool vis[maxn]; 9 int girl[maxn]; 10 bool check(int x){ 11 for(int i=0;i<n;i++){ 12 if(mat[x][i]==1&&!vis[i]){ 13 vis[i]=1; 14 if(girl[i]==-1||check(girl[i])){ 15 girl[i]=x; 16 return 1; 17 } 18 } 19 } 20 return 0; 21 } 22 int main() 23 { 24 //freopen("test.in","r",stdin); 25 while(scanf("%d",&n)!=EOF){ 26 memset(mat,0,sizeof(mat)); 27 memset(girl,-1,sizeof(girl)); 28 for(int i=0;i<n;i++){ 29 scanf("%d: (%d)",&a,&b); 30 while(b--){ 31 scanf("%d",&c); 32 mat[a][c]=1; 33 } 34 } 35 int ans=0; 36 for(int j=0;j<n;j++){ 37 memset(vis,0,sizeof(vis)); 38 if(check(j))ans++; 39 } 40 /*通过最大二分匹配,我们得到了最大匹配数,但是由于男生女生 41 都算了一遍,所以是不是就得除以二。这样就是最大匹配数了*/ 42 printf("%d\n",n-ans/2); 43 } 44 return 0; 45 }
hduoj-----(1068)Girls and Boys(二分匹配),布布扣,bubuko.com
hduoj-----(1068)Girls and Boys(二分匹配)
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/gongxijun/p/3927936.html