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. 如何使用 channel

    如何使用 Channel 例子来自于Concurrency is not parallelism Google Search: A fake framework v1.0 var ( Web = fa ...

  2. 巧用Scrum与Kanban

    本文来自网易云社区 文\屈鹏飞 在互联网行业的项目管理实践中,敏捷和精益一直是大家所提倡的思想,其中Scrum和Kanban方法作为即敏捷又精益的典型代表,许多PM都在研究,笔者近期也在学习和实施Sc ...

  3. ecliplse里tomcat正常启动后http://localhost:8080/报错404

    如下图所示,新建一个工作区间,添加tomcat之后通过ecliplse启动tomcat之后: 访问http://localhost:8080/出现404: 解决方法: 1.确保tomcat里面所有项目 ...

  4. 【10.2.3】ArcGIS Runtime for Android搭建开发环境过程中问题具体解释

    一.Visual Studio Ultimate2012安装过程问题 1.问题描写叙述 安装完毕后,您将看到一条消息,指示安装程序已完毕.但并非全部的功能具有已正确安装.以及下面警告消息: Micro ...

  5. 八大排序算法的python实现(八)简单选择排序

    代码: #coding:utf-8 #author:徐卜灵 # L = [6, 3, 2, 32, 5, 4] def Select_sort(L): for i in range(0,len(L)) ...

  6. 解决tomcat启动 startup.bat的时候一闪而过(就是java环境变量的配置)

    系统变量配置:(解决tomcat启动 startup.bat的时候一闪而过) JAVA_HOME C:\Program Files (x86)\Java\jdk1.7.0_25 =========== ...

  7. Unity---动画系统学习(6)---Avatar Mask动画融合、Layers动画分层、IK反向动力学

    1. 介绍 Avatar Mask(动画融合) 前面我们一直介绍的都是动画混合,一般用于解决边跑边转弯的问题.而动画融合一般用于解决例如边跑边挥手的问题. 简单说就是让跑步去控制腿的骨骼,挥手控制手的 ...

  8. [APIO2009]抢掠计划 tarjan缩点+spfa BZOJ1179

    题目描述 Siruseri 城中的道路都是单向的.不同的道路由路口连接.按照法律的规定, 在每个路口都设立了一个 Siruseri 银行的 ATM 取款机.令人奇怪的是,Siruseri 的酒吧也都设 ...

  9. 安装GCC-8.3.0及其依赖

    目录 目录 1 1. 前言 1 2. 安装日期 1 3. GCC国内镜像下载地址 2 4. GCC的依赖库 2 4.1. gmp库 2 4.2. mpfr库 2 4.3. mpc库 2 4.4. m4 ...

  10. ARKit的使用

    //创建场景 let scene = SCNScene() /* //1.几何 let box = SCNBox.init(width: 0.1, height: 0.1, length: 0.1, ...