The antidote or the poison?
Time limit: 1 s
Space limit: 128000 KB
Title 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
Search in a state-compressed manner
Because there are only two states of each disease
Use a 01 string to store this state
Pruning: If this state exists, do not queue
If you get the final solution, exit directly.
Code
var i,j,k:longint; Dui:array[1..1024]of string; Init:array[1..100,1..10]of Longint; Deep:array[1..1024]of Longint; N,m:longint; Ok:boolean; Head,tail:longint; temp:string; Pear:boolean;function Pan (x:string): boolean; var i:longint; Begin Pan:=true; For I:=1 to N does if x[i]= ' 1 ' then exit (false); Exit (TRUE); End;begin readln (n,m); For I:=1 to M does for J:=1 to n do read (init[i,j]); Ok:=false; Head:=1; Tail:=1; deep[1]:=0; Dui[1]:= "; For I:=1 to n do dui[1]:=dui[1]+ ' 1 '; while (Head<=tail) and (not OK) does begin for i:=1 to M do begin pear:=false; Temp:=dui[head]; For J:=1 to n does begin if init[i,j]=1 then temp[j]:= ' 0 '; If Init[i,j]=-1 then temp[j]:= ' 1 '; End For j:=1 to tail does if temp=dui[j] then pear:=true; If not Pear then BEGIN Inc (tail); Dui[tail]:=temp; Deep[tail]:=deep [Head]+1; If Pan (temp) THEN BEGIN Writeln (Deep[tail]); Halt End End End Inc (head); End Writeln (' The patient would be dead. '); End.
Noip Eve: Codevs, antidote or poison