delightful world

时间限制(C/C++):20000MS/30000MS          运行内存限制:65536KByte
总提交:33            测试通过:10

描述

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 of n 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 5 correct 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?

输入

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 n numbers which are 0 or 1) and the system's response (an integer from 0 to 5 inclusively), 6 <= n <= 35, 1 <= m <= 10.

输出

Print the single number which indicates how many possible combinations of code exist that proves the system is working with no problems.

样例输入

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.

题目来源

BJFUACM

题目大意:给你n,m表示下面的矩阵是m*n的,用0、1的行去跟矩阵的每行对比,看对应位置相同的是否为每行后面的数字,如果所有的行都能满足,那么就是一种方案,问你总的方案数。

解题思路:枚举第一行正确的位置,然后跟下面的行去比较。

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<string>
#include<iostream>
#include<queue>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
#define mid (L+R)/2
#define lson rt*2,L,mid
#define rson rt*2+1,mid+1,R
const int INF = 0x3f3f3f3f;
const int maxn = 1e2 + 300;
int a[maxn], v[maxn], Map[maxn][maxn];
int n, m;
int dfs(int cur,int dep){
if(dep > a[1]){
for(int i = 2; i <= m; i++){
int tmp = 0;
for(int j = 1; j <= n; j++){
if(v[j]){
if(Map[i][j] == Map[1][j]){
tmp++;
}
}else{
if(Map[i][j] != Map[1][j]){
tmp++;
}
}
}
if(tmp != a[i]){
return 0;
}
}
return 1;
}
int ret = 0;
for(int i = cur; i <= n; i++){
v[i] = 1;
ret += dfs(i+1,dep+1);
v[i] = 0;
}
return ret;
}
int main(){
char s[333];
while(scanf("%d%d",&n,&m)!=EOF){
for(int i = 1; i <= m; i++){
scanf("%s",s);
for(int j = 1; j <= n; j++){
Map[i][j] = s[j-1] - '0';
}
scanf("%d",&a[i]);
}
int res = dfs(1,1);
printf("%d\n",res);
}
return 0;
}

  

BJFU 1551 ——delightful world——————【暴搜】的更多相关文章

  1. 【BZOJ-3033】太鼓达人 欧拉图 + 暴搜

    3033: 太鼓达人 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 204  Solved: 154[Submit][Status][Discuss] ...

  2. c++20701除法(刘汝佳1、2册第七章,暴搜解决)

    20701除法 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述     输入正整数n,按从小到大的顺序输出所有 ...

  3. Codeforces Round #238 (Div. 2) D. Toy Sum 暴搜

    题目链接: 题目 D. Toy Sum time limit per test:1 second memory limit per test:256 megabytes 问题描述 Little Chr ...

  4. poj 3080 Blue Jeans(水题 暴搜)

    题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...

  5. Sicily1317-Sudoku-位运算暴搜

    最终代码地址:https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1317.c 这题博主刷了1天,不是为了做出来,AC ...

  6. codeforces 339C Xenia and Weights(dp或暴搜)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Xenia and Weights Xenia has a set of weig ...

  7. Usaco 2.3 Zero Sums(回溯DFS)--暴搜

    Zero SumConsider the sequence of digits from 1 through N (where N=9) in increasing order: 1 2 3 ... ...

  8. HDU4403(暴搜)

    A very hard Aoshu problem Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  9. suoi62 网友跳 (暴搜+dp)

    传送门 sbw太神啦orz 首先N<=20可以直接暴搜 然后玄学剪枝可以过18个点 那么N<=40的时候,就把它拆成两半分别暴搜,再用dp拼起来 对于前半段,设f[i][j]是开始高度为i ...

随机推荐

  1. SpringMVC+Hibernate 项目开发之二 (STS整合Maven)

    为什么用STS不用Eclipse,主要是Eclipse集成Maven把我整疯了,最后估计原因除在网速上了. 其实用了STS以后发现还真比Eclipse好用点. STS本身集成有Maven的,但是默认的 ...

  2. Delphi XE8中开发DataSnap程序常见问题和解决方法 (-)启动创建好的DBExpress工程时候报错了!

    当我们成功创建了使用DBExpress的DataSnap的服务器和客户端程序后,我们关闭了当前工程,当我们再次打开时候,有可能会出现这样的问题: 问题原因:这个问题是因为当前工程组默认启动的是客户端工 ...

  3. Weekly Contest 117

    965. Univalued Binary Tree A binary tree is univalued if every node in the tree has the same value. ...

  4. [SinGuLaRiTy] 2017 百度之星程序设计大赛 初赛A

    [SinGuLaRiTy-1036] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 小C的倍数问题 Time Limit: 2000/100 ...

  5. json_decode转换数组过程中,结果为null处理办法,百分之百有效

    json_decode这个函数是json_encode的反函数,一般传递数据的时候为了压缩数据,会将数组格式的数据转换成json格式,用到的函数就是json_encode,然后接收到数据之后再用jso ...

  6. PC站与H5移动站最佳适配方案

    HTML5是目前HTML的最屌版本,同时也是建设移动站的最佳技术.百度适时推出PC站与H5移动站的最佳适配方案,对站长而言实在是久旱逢甘霖.详情如下: PC站与H5移动站最佳适配方案 pc端: 在pc ...

  7. CentOS7.4关闭防火墙

    //临时关闭 systemctl stop firewalld //禁止开机启动 systemctl disable firewalld Removed symlink /etc/systemd/sy ...

  8. 多线程 NSOpeartion 的使用

    NSOperation简介 相对于 GCD ,具有面向对象的特征,比 GCD 更简单易用,代码可读性强 NSOperatioin 单独使用时, 不具有开辟新线程的能力, 只是同步执行操作, 需要配合 ...

  9. 使用Jenkins进行Android自动打包,自定义版本号等信息【转】

    之前App在提交测试和最终部署的过程中App打包一直是由开发人员来完成的,由于项目比较大, 再加上Android打包本身就比较慢,所以每次打包还是很耗时的.并且按照严格的研发流程来讲,开发人员应该只负 ...

  10. get请求和post的请求的区别

    https://www.cnblogs.com/logsharing/p/8448446.html