2594 antidote or poison?

Source: Internet
Author: User

2594 antidote or poison?

time limit: 1 sspace limit: 128000 KBtitle level: Diamonds Diamond SolvingTitle 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

Category labels Tags Click here to expandDynamic Programming Heuristic Search Search
#include <iostream>#include<queue>using namespacestd;intf[101][ One],a[1025],n,m;queue<int>que;intjs[ A];intMain () {//pressure js[]+ wide search quejs[1]++;  for(intI=2; i<= One; i++) Js[i]=js[i-1]<<1; CIN>>n>>m;  for(intI=1; i<=m;i++)         for(intj=1; j<=n;j++) Cin>>F[i][j]; intk=js[n+1]-1;    Que.push (k);  while(!Que.empty ()) {        intp=Que.front ();        Que.pop (); if(!p) {cout<<a[p]<<Endl; return 0; }         for(intI=1; i<=m;i++){            ints=0;  for(intj=1; j<=n;j++){                if(f[i][j]==0&& (p&Js[j])) {s+=Js[j]; }                if(f[i][j]==-1) {s+=Js[j]; }            }            if(!a[s]&&s!=k) {A[s]=a[p]+1;            Que.push (s); } }} cout<<"The patient would be dead."<<Endl; return 0;}

2594 antidote or poison?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.