2724 Purifying Machine//MAXMATCH
Time Limit: 2000MS
Memory Limit: 65536K
Total Submissions: 2573
Accepted: 693
Description
Mike is the owner of a cheese factory. He has 2
N cheeses and each cheese is given a binary number from 00...0 to 11...1. To keep his cheese free from viruses, he made himself a purifying machine to clean virus-infected cheese. As a talented programmer, his purifying machine is built in a special way. His purifying machine has N switches, each switch has three states, 1, 0 and *. An operation of this machine is a cleaning action according to the states of the N switches. During one operation, at most one switch can be turned to state *, which can substitute for either 1 or 0. When the machine is turned to a specific state, an operation will clean all the cheeses with corresponding binary numbers. For example, if N equals 6 and the switches are turned to 01*100, the cheeses numbered 010100 and 011100 are under operation by the machine.
One day, Mike's machine was infected. When Mike found out, he had already done some operations and the cheeses operated by this infected machine were infected too. He cleaned his machine as quickly as he could, and now he needs to clean the infected cheeses with the minimum number of operations. If a cheese is infected, cleaning this cheese with the machine one or more times will make this cheese free from virus again; but if a cheese is not infected, operation on this cheese will make it go bad.
Now given the infected operations Mike has done, you need to find out the minimum number of operations that must be performed to clean all the infected cheeses without making any clean cheese go bad.
Input
There are several test cases. Each test case starts with a line containing two numbers N and M (1 <= N <= 10, 1 <= M <= 1000). N is the number of switches in the machine and M is the number of infected operations Mike has done. Each of the following M lines contains a switch state of the machine. A test case with N = M = 0 ends the input and should not be processed.
Output
For each test case, output one line containing an integer, which is the minimum number of operations Mike needs to do.
Sample Input
3 3
*01
100
011
0 0
Sample Output
2
Source
Beijing 2005
#include
#include
int n,m,gx,gy;
bool f[1025];
int h[1025],link[1025];
bool mat[1025][1025];
bool can(int t)
{
for(int i=0;i
{
f[i]=1;
if(link[i]==-1||can(link[i]))
{
link[i]=t;
return true;
}
}
return false;
}
int MaxMatch()
{
int num=0;
memset(link,-1,sizeof(link));
for(int i=0;i
memset(f,0,sizeof(f));
if(can(i)) num++;
}
return num;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==0&&m==0) break;
gx=0,gy=0;
memset(f,0,sizeof(f));
for(int i=1;i<=m;i++)
{
char s[100];
scanf("%s",s);
int a=0,b=0;
for(int j=0;j
if(s[j]=='*')
{
a=a*2+1;
b=b*2;
}
else
{
a=a*2+(s[j]-'0');
b=b*2+(s[j]-'0');
}
}
if(f[a]==0) h[gx++]=a,f[a]=1;
if(f[b]==0) h[gx++]=b,f[b]=1;
}
gy=gx;
memset(mat,false,sizeof(mat));
int i=0,j=0;
for(i=0;i
int c=h[i]^h[j];
if(c&&((c&(c-1))==0)) mat[i][j]=1;
}
printf("%d/n",gy-MaxMatch()/2);
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
cocos2d Lua 학습(一)ios에서 루아 함수 호출 및 전참 방법 lua 코드: 출력 결과: lua 호출 C++ 방법: add 함수: lua 코드: 출력 결과: 함수를 호출합니다. 함수를 호출하려면 다음 협의를 따르십시오. 우선, 호출할 함...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.