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. WPF中在摄像头视频上叠加控件的解决方案

    一.视频呈现 前段时间,在一个wpf的项目中需要实时显示ip摄像头,对此的解决方案想必大家都应该知道很多.在winform中,我们可以将一个控件(一般用panel或者pictruebox)的句柄丢给摄 ...

  2. .Net Core 项目引用本地类库方式(一)

    最近了解到.NET Core 项目,引用本地类库DLL的方式有三种 1.非同解决方案下的引用,直接引用,浏览,找到对应的DLL,然后确定引用. 这种方式有个不好的地方就是,如果引用的DLL文件里面,也 ...

  3. LogNet4

    ASP.Net MVC 项目中添加LogNet4 1,创建ASP.NET MVC项目 2,NuGet或者直接下载log4net.dll 并安装 3 在配置文件 web.config 加入 如下代码 & ...

  4. .NET&C#的异常处理

    应用程序未捕获异常的处理 处理未捕获的异常是每个应用程序起码有的功能 无论是Windows窗体程序还是WPF程序,我们都看到捕获的异常当中分为"窗体线程异常"和"非窗体线 ...

  5. WinForm中ListBox的使用

    获取选中数据:listbox.SelectedItem as XXX 重绘每一行item DrawMode设置为DrawMode.OwnerDrawVariable 然后实现DrawItem(obje ...

  6. NSCalendar日历

    前言 NSCalendar 对世界上现存的常用的历法进行了封装,既提供了不同历法的时间信息,又支持日历的计算. NSCalendar -- 日历类,它提供了大部分的日期计算接口,并且允许您在NSDat ...

  7. VSCode提示pylint isnot installed

    1.下载所需扩展 在https://www.lfd.uci.edu/~gohlke/pythonlibs/中下载所需扩展,我下载的是:pylint-2.1.1-py2.py3-none-any.whl ...

  8. 1235: 入学考试[DP]

    1235: 入学考试 [DP] 时间限制: 1 Sec 内存限制: 128 MB 提交: 37 解决: 12 统计 题目描述 辰辰是个天资聪颖的孩子,他的梦想是成为世界上最伟大的医师.为此,他想拜附近 ...

  9. 【离散数学】 SDUT OJ 谁是作案嫌疑人?

    谁是作案嫌疑人? Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 刑侦大队对涉及六个嫌 ...

  10. python获取函数参数默认值的两种方法

    1.使用函数的__defaults__魔术方法 demo: # coding=utf-8 def f(a,b,c=1): pass f.__defaults__ 输出结果: (1,) 2.使用insp ...