标签:
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 20874 | Accepted: 9421 |
Description
Input
Output
Sample Input
5 5 2 2 5 3 2 3 4 2 1 5 3 1 2 5 1 2
Sample Output
4
题意:奶牛只在指定的摊位才肯产奶,第一行输入n,m分别代表母牛数量和摊位的数量,接下来m行,第i行就代表第i头奶牛,每行开头一个数k代表接下来这一行要输入的摊位号
匈牙利算法模板都快忘了 复习一下 以后也不能老刷模板题
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define MAX 210
using namespace std;
int n,m;
int cow[MAX][MAX],space[MAX];
int vis[MAX];
int find(int x)
{
int i,j;
for(i=1;i<=m;i++)
{
if(cow[x][i]&&!vis[i])
{
vis[i]=1;
if(space[i]==0||find(space[i]))
{
space[i]=x;
return 1;
}
}
}
return 0;
}
int main()
{
int i,j,t,a;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(cow,0,sizeof(cow));
memset(space,0,sizeof(space));
for(i=1;i<=n;i++)
{
scanf("%d",&t);
for(j=1;j<=t;j++)
{
scanf("%d",&a);
cow[i][a]=1;
}
}
int sum=0;
for(i=1;i<=n;i++)
{
memset(vis,0,sizeof(vis));
if(find(i))
sum++;
}
printf("%d\n",sum);
}
return 0;
}
poj 1274 The Perfect Stall【匈牙利算法模板题】
标签:
原文地址:http://www.cnblogs.com/tonghao/p/4806992.html