hdu 1150 Machine Schedule (经典二分匹配)

//A组n人 B组m人
//最多有多少人匹配 每人仅仅有匹配一次
# include<stdio.h>
# include<string.h>
# include<algorithm>
using namespace std;
int n,m,k;
int pp[1100][1100],map[1100],vis[1100];
int bfs(int x)//二分匹配模板
{
	for(int i=1;i<=m;i++)//B组中的人来迎合匹配
	{
		if(!vis[i]&&pp[x][i])
		{
			vis[i]=1;
			if(!map[i]||bfs(map[i]))//b中i还没匹配或与之匹配的A组中的数(map[i])还能找到其它人匹配
			{
				map[i]=x;
				return 1;
			}
		}
	}
	return 0;
}
int main()
{
	int count,i,a,b,c;
	while(~scanf("%d",&n),n)
	{
		memset(pp,0,sizeof(pp));//是否匹配
		memset(map,0,sizeof(map));
		scanf("%d%d",&m,&k);
		for(i=0;i<k;i++)
		{
			scanf("%d%d%d",&a,&b,&c);
		    pp[b][c]=1;
		}
		count=0;//匹配数
	    for(i=1;i<=n;i++)//A组中的人进行匹配
		{
			memset(vis,0,sizeof(vis));
			if(bfs(i))
				count++;
		}
		printf("%d\n",count);
	}
	return 0;
}
时间: 2024-08-27 21:06:32

hdu 1150 Machine Schedule (经典二分匹配)的相关文章

hdu 1150 Machine Schedule(二分匹配,简单匈牙利算法)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6733    Accepted Submission(s): 3375 Problem Description As we all know, mach

杭电 HDU ACM 1150 Machine Schedule(二分匹配)

Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7056    Accepted Submission(s): 3537 Problem Description As we all know, machine scheduling is a very classical problem in compu

HDU 1150 Machine Schedule(二分图匹配)

解题思路: 本题要求的为最小点覆盖,最小点覆盖 == 最大匹配,要注意初始为模式0,没有消耗,所以模式0不需要连边. #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <algorithm> #include <vector> #include <cmath> #include <queue>

HDU 1150:Machine Schedule(二分匹配,匈牙利算法)

Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5371    Accepted Submission(s): 2658 Problem Description As we all know, machine scheduling is a very classical problem in compu

hdu 1150 Machine Schedule(二分图-最小顶点覆盖)

Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5424    Accepted Submission(s): 2691 Problem Description As we all know, machine scheduling is a very classical problem in compu

hdu 1150 Machine Schedule(最小顶点覆盖)

pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5424    Accepted Submission(s): 2691 Problem Description As we all know, machine scheduling is a very classical pro

HDU 1150 Machine Schedule (二分匹配)

Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Description As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduli

hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配

Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1150 Description As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history.

hdu 1150 Machine Schedule 最少点覆盖

Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1150 Description As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history.