POJ 2239题

//类型:二分图的最大匹配:使用匈牙利算法实现
#include <stdio.h>
#include <string.h>
//#include <conio.h>
#define arraysize1 301       //课程数
#define arraysize2 85        //时间(将时间统一化成节数)
int map[arraysize1][arraysize2];
int match[arraysize1];
bool final[arraysize1];
int n;
bool DFS(int p)
{
     int i,j;
     int temp;
     for(i=1;i<85;++i)
     {
         if(map[p][i] && !final[i])
         {
              final[i] = true;
              temp = match[i];
              match[i] = p;
              if(temp==0 || DFS(temp)) return true;
              match[i] = temp;       
         }
     }
     return false;
}
int mat()
{
    int i,j;
    int maxmatch = 0;
    for(i=1;i<n+1;++i)
    {
        memset(final,0,sizeof(final));
        if(DFS(i)) maxmatch++;
    }
    return maxmatch;
}
int main()
{
    //freopen("1.txt","r",stdin);
    int i,j;
    while(scanf("%d",&n)!=EOF)
    {
         int t;
         memset(map,0,sizeof(map));
         memset(match,0,sizeof(match));
         for(j=1;j<n+1;++j)
         {
            int p,q;
            int time;
            scanf("%d",&t);
            for(i=1;i<t+1;++i)
            {
                scanf("%d%d",&p,&q);
                time = (p-1)*12+q;  //将时间化成节数
                map[j][time] = 1;
            }           
         }
         printf("%d\n",mat());
    }
    //getch();
    return 0;
}

转载于:https://www.cnblogs.com/north_dragon/archive/2010/05/06/1729292.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值