2594 antidote or poison?
time limit: 1 sspace limit: 128000 KBtitle level: Diamonds Diamond SolvingView Run ResultsTitle Description
Description
Smart developed a cure for all kinds of symptoms, but he was careless, each medicine is a little bit wrong with a little raw material, so these drugs can be cured of certain conditions at the same time and make people suffer from some other conditions (you may ask that ...) Is that the antidote or the poison? ) ..., after smart efforts, finally understand the specific performance of each drug, he will be cured of each medicine and can make a list of symptoms of the disease to you, and then you have to follow this list to find a cure all the symptoms of the minimum pharmaceutical combination ... By the way, the number of illnesses is not more than 10, and his medicine is not finished, that is, each agent can be reused.
Enter a description
Input Description
The first line in your list is the total number of illnesses N (1≤n≤10). The second line is the kind of the medicament m (0<m≤100).
The following are m lines, each line has n digits separated by a space, the file of the nth number of line i+2, if the number of J is 1, it means that the first drug can cure the disease j (if the disease is cured, no such disease is not affected), if 0 means no effect, If 1 means that it can cause the disease (no disease, no illness). Any two kinds of properties are different for smart-based drugs.
Output description
Output Description
You just have to output the minimum number of potions you can, in fact, you may have exhausted all the drugs and can not cure all the disease, so you just output "the patient will be dead." You can do it.
Sample input
Sample Input
3
2
1 0 1
-1 1 0
Sample output
Sample Output
2
Data range and Tips
Data Size & Hint
1≤n≤10
0<m≤100
Binary, hash, heavy and wide search
#include <cstdio>#include<iostream>#defineM 1100using namespacestd;structnode{intF[M];//the condition of the patient intDep//Number of steps};node q[m];intA[m][m],num[m],hash[m],n,m,head,tail,sum,flag;voidBFs () { while(head<=tail) { for(intI=1; i<=n;i++) { inttot=0; Tail++;tot=0; for(intj=1; j<=m;j++) { if(a[i][j]==1) q[tail].f[j]=1; Else if(a[i][j]==0) q[tail].f[j]=Q[head].f[j]; Elseq[tail].f[j]=0; if(q[tail].f[j]==1) tot+=Num[j]; } if(!Hash[tot]) {Hash[tot]=1; Q[TAIL].DEP=q[head].dep+1; if(tot==sum) {printf ("%d", Q[TAIL].DEP); Flag=1; return; } } Elsetail--; } head++; }}voidinit () {num[1]=2; Sum=2; for(intI=2; i<=m;i++) Num[i]=num[i-1]*2, Sum+=num[i];}intMain () {scanf ("%d%d",&m,&N); Init (); for(intI=1; i<=n;i++) for(intj=1; j<=m;j++) scanf ("%d",&A[i][j]); BFS (); if(!flag) printf ("The patient would be dead."); return 0;}
View Code
Antidote or poison (Codevs 2594)