2594 or 2594
Time Limit: 1 s space limit: 128000 KB title level: DiamondQuestionView running resultsDescriptionDescription
Smart developed an antidote to all kinds of symptoms, but he was not careful. Every kind of medicine was equipped with a little wrong raw material, therefore, these medicines may cure some diseases and cause some other diseases (You may ask... Is it an antidote or a poison ?)......, After Smart's efforts, he finally figured out the specific performance of each medicine. He will list the symptoms that each medicine can cure and the symptoms that can cause human problems to you, then you need to find out the minimal combination of medicines that can cure all diseases according to this list ...... By the way, there are no more than 10 cases of illness, and his medicine is useless, that is, each medicine can be reused.
Input description
Input Description
The first line in your list is the total number of diseases n (1 ≤ n ≤ 10 ). The second row is the agent type m (0 <m ≤ 100 ).
The following are m rows. n numbers in each row are separated by spaces. If the number of j is 1, indicates that the type I medicine can cure disease j (if it is affected, it will be cured, and no such disease will be affected), if it is 0, it indicates no effect, if it is-1, it indicates that this disease can be exploited (no disease, no impact on the disease ). Smart medicines have different performance.
Output description
Output Description
You only need to output The minimum number of agents. In fact, you may have used up all The medicines and cannot cure all The diseases. In this case, you only need to output "The patient will be dead..
Sample Input
Sample Input
3
2
1 0 1
-1 1 0
Sample output
Sample Output
2
Data range and prompt
Data Size & Hint
1 ≤ n ≤ 10
0 <m ≤ 100
Use dp [I] to represent the minimum number of steps required to reach the I state
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<queue> 6 #include<algorithm> 7 #define lli long long int 8 using namespace std; 9 const int MAXN=1001;10 const int maxn=0x7fffff;11 inline void read(int &n)12 {13 char c='+';int x=0;bool flag=0;14 while(c<'0'||c>'9')15 {c=getchar();if(c=='-')flag=1;}16 while(c>='0'&&c<='9')17 {x=(x<<1)+(x<<3)+c-48;c=getchar();}18 flag==1?n=-x:n=x;19 }20 int a[MAXN][MAXN];21 int dp[MAXN];22 int n,m;23 int main()24 {25 read(n);read(m);26 for(int i=1;i<=m;i++)27 for(int j=1;j<=n;j++)28 read(a[i][j]);29 for(int i=0;i<=(1<<n);i++)30 dp[i]=maxn;31 dp[0]=0;32 for(int i=0;i<=(1<<n);i++)33 {34 for(int j=1;j<=m;j++)35 {36 int now=i;37 for(int k=1;k<=n;k++)38 {39 if(a[j][k]==0) continue;40 if(a[j][k]==1) now=now|(1<<k-1);41 if(a[j][k]==-1&&now&(1<<k-1)) now^=(1<<k-1); 42 }43 dp[now]=min(dp[now],dp[i]+1);44 }45 }46 if(dp[(1<<n)-1]==maxn)printf("The patient will be dead.\n");47 else printf("%d\n",dp[(1<<n)-1]);48 return 0;49 }