Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

50题,小小的纪念下,代码留下,纯粹的二分匹配匈牙利算法模板题

Posted by yuanchuanshun at 2010-07-29 15:34:41 on Problem 1274
/*1274 Accepted 424K 16MS G++ 946B 2010-07-29 15:33:19 */
#include<stdio.h>
#include<string.h>
#define arr 201
int N,M,pre[arr];
bool map[arr][arr],used[arr];
bool find(int x)
{
     int i;
     for(i=1;i<=M;i++)
     {
         if(!used[i]&&map[x][i])
         {
             used[i]=1;
             if(pre[i]==-1||find(pre[i]))
             {
                pre[i]=x;
                return 1;
             }
         }
     }
     return 0;
}
int MMG()
{
    int i,count=0;
    memset(pre,-1,sizeof(pre));
    for(i=1;i<=N;i++)
    {
        memset(used,0,sizeof(used));
        if(find(i))
        count++;
    }
    return count;
}
int main()
{
    int i,j,t,num;
    while(scanf("%d%d",&N,&M)!=EOF)
    {
        memset(map,0,sizeof(map));
        for(i=1;i<=N;i++)
        {
            scanf("%d",&num);
            for(j=1;j<=num;j++)
            scanf("%d",&t),map[i][t]=1;
        }
        int ans=MMG();
        printf("%d\n",ans);
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator