计蒜客 delightful world

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 ofnn numbers, and every number is a 00 or 11, he has made mm 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 55correct 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 nn and mm, which represent the number of numbers in the code and the number of attempts made by Siny.

Then follow mm lines, each containing space-separated si and ci which correspondingly indicate Siny's attempt (a line containing nnnumbers which are 00 or 11) and the system's response (an integer from 00 to 55 inclusively), 6 \leq n \leq 35, 1 \leq m \leq 106n35,1m10.

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 33 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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值