POJ-2239-Selecting Courses
http://poj.org/problem?id=2239
二分图匹配
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 500
int map[N][N];
int state[N];
int result[N];
int n,m;
int find(int a)
{
int i;
for(i=1;i<=m;i++)
if(!state[i]&&map[a][i])
{
state[i]=1;
if(result[i]==0||find(result[i]))
{
result[i]=a;
return 1;
}
}
return 0;
}
int main()
{
int i,num,a,b,ans;
while(scanf("%d",&n)!=EOF)
{
memset(map,0,sizeof(map));
m=7*12;
for(i=1;i<=n;i++)
{
scanf("%d",&num);
while(num--)
{
scanf("%d %d",&a,&b);
map[i][(a-1)*12+b]=1;
}
}
ans=0;
memset(result,0,sizeof(result));
for(i=1;i<=n;i++)
{
memset(state,0,sizeof(state));
if(find(i))
ans++;
}
printf("%d\n",ans);
}
return 0;
}