把每一个颜色单独求最大匹配,如果大于m,记为不能砸碎的颜色
There will be a n*n matrix board on the ground, and each grid will have a color balloon in it.And the color of the ballon will be in the range of [1, 50].After the referee shouts "go!",you can begin to crash the balloons.Every time you can only choose one kind of balloon to crash, we define that the two balloons with the same color belong to the same kind.What's more, each time you can only choose a single row or column of balloon, and crash the balloons that with the color you had chosen. Of course, a lot of students are waiting to play this game, so we just give every student k times to crash the balloons.
Here comes the problem: which kind of balloon is impossible to be all crashed by a student in k times.
1 1 1 2 1 1 1 1 2 2 1 1 2 2 2 5 4 1 2 3 4 5 2 3 4 5 1 3 4 5 1 2 4 5 1 2 3 5 1 2 3 4 3 3 50 50 50 50 50 50 50 50 50 0 0
-1 1 2 1 2 3 4 5 -1
#include<stdio.h>
#include<string.h>
#define maxn 150
bool Map[maxn][maxn];
bool Flag[maxn];
int Mark[maxn];
int a[maxn][maxn];
int b[maxn];
bool Find(int x,int n)
{
int i;
for(i=1;i<=n;i++)
{
if(!Map[x][i]||Flag[i])
continue;
Flag[i]=true;
if(!Mark[i]||Find(Mark[i],n))
{
Mark[i]=x;
return true;
}
}
return false;
}
int main()
{
int n,m;
int i,j,k;
int x,y,z;
while(scanf("%d%d",&n,&m),n&&m)
{
k=1;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
scanf("%d",&a[i][j]);
for(i=1;i<=50;i++)
{
z=0;
memset(Mark,0,sizeof(Mark));
for(x=1;x<=n;x++)
for(y=1;y<=n;y++)
if(a[x][y]==i)
Map[x][y]=true;
else
Map[x][y]=false;
for(x=1;x<=n;x++)
{
memset(Flag,false,sizeof(Flag));
if(Find(x,n))
z++;
}
if(z>m)
b[k++]=i;
}
if(k==1)
printf("-1\n");
else
{
printf("%d",b[1]);
for(i=2;i<k;i++)
printf(" %d",b[i]);
printf("\n");
}
}
return 0;
}