Siny was once a very happy boy. But one day, something awful happened. He felt so sorrowful and he decided to leave the place where he resided at now. So he packs up his clothes and takes a plane to a completely new world called "CareFree world", people there has no worried at all and live in a delightful life. But when he arrives there, he found he has to do something challengeable so that he can be allowed to enter the delightful world.
His task is to guess the code. A code cosists ofn numbers, and every number is a 0 or 1, he has made m attempts to guess the code. After each guess, a system will tell him how many position stand the right numebers. But he is unlucky that he never guesses more than 5correct numbers. So he doubts the system for having mistakes in telling him the right numbers in right position.
Can you tell him how many possible combinations of code exist that proves the system is working with no problems?
Input:
There are multiple cases.
For each case, the first input line contains two integers n and m, which represent the number of numbers in the code and the number of attempts made by Siny.
Then follow m lines, each containing space-separated si and ci which correspondingly indicate Siny's attempt (a line containing nnumbers which are 0 or 1) and the system's response (an integer from 0 to 5 inclusively), 6≤n≤35,1≤m≤10.
Output:
Print the single number which indicates how many possible combinations of code exist that proves the system is working with no problems.
样例1
输入:
6 3
000000 2
010100 4
111100 2
6 3
000000 2
010100 4
111100 0
输出:
1
0
提示信息
In the first example, there exists one possible combination that is 010111, which satisfies all the 3 results the system tells Siny, and it proves that the system is working fine without any problems.
解体思路:给你n串字符串,告诉你,该字符串与原串有多少个字符是相同的,问这样的满足字符串的原串有多少个.因为最多10个字符串,最长35,所以直接暴搜就行了.
代码如下:
#include<stdio.h>
#include<string.h>
char map[15][40];
int len[15];
int vist[40];
int n,m;
int dfs(int cur,int l){
if(l>len[0]){
for(int i=1;i<m;i++){
int t=0;
for(int j=0;j<n;j++){
if(vist[j]){
if(map[0][j]==map[i][j])
t++;
}
else{
if(map[0][j]!=map[i][j])
t++;
}
}
if(t!=len[i])
return 0;
}
return 1;
}
int res=0;
for(int i=cur;i<n;i++){
vist[i]=1;
res+=dfs(i+1,l+1);
vist[i]=0;
}
return res;
}
int main(){
int i;
while(scanf("%d%d",&n,&m)!=EOF){
for(i=0;i<m;i++){
scanf("%s",map[i]);
scanf("%d",&len[i]);
}
memset(vist,0,sizeof(vist));
printf("%d\n",dfs(0,1));
}
return 0;
}