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. Socket 简易静态服务器 WPF MVVM模式(四)

    最重要的一个类Socket类 using System; using System.Collections.Generic; using System.IO; using System.Linq; u ...

  2. Deferred Shading,延迟渲染(提高渲染效率,减少多余光照计算)【转】

    Deferred Shading,看过<Gems2> 的应该都了解了.最近很火的星际2就是使用了Deferred Shading. 原帖位置:   http://blog.csdn.net ...

  3. 《javascript 高级程序设计》 笔记1 1~7章

    chapter 2 在html中使用JavaScript chapter 3 基本概念 EMCAscript 语法 变量,函数名和操作符都区分大小写. 使用var定义的变量将成为定义该变量的作用域中的 ...

  4. php文件下载方法收藏(附js下载技巧)

    function down($url){ header('Content-Description: File Transfer'); header('Content-Type: application ...

  5. 洛谷 P2330 [SCOI2005]繁忙的都市(最小生成树)

    嗯... 题目链接:https://www.luogu.org/problemnew/show/P2330 这道题的问法也实在是太模板了吧: 1.改造的道路越少越好 2.能够把所有的交叉路口直接或间接 ...

  6. ScrollView-电影列表

    ScrollView 的使用import React, { Component } from 'react';import { Platform, StyleSheet, Text, View, Sc ...

  7. 多线程 NSThread 的使用

    NSThread简介 使用NSThread 实现多线程,需要手动管理线程的生命周期, 一.线程的创建 //1.实例方法创建,,需要手动启动线程 NSThread *thread = [[NSThrea ...

  8. 洛谷 P4108 / loj 2119 [HEOI2015] 公约数数列 题解【分块】

    看样子分块题应该做的还不够. 题目描述 设计一个数据结构. 给定一个正整数数列 \(a_0, a_1, \ldots , a_{n-1}\),你需要支持以下两种操作: MODIFY id x: 将 \ ...

  9. leetcode 493 Reverse Pairs

    题意:给定一个数组nums,求若 i<j and nums[i] > 2*nums[j] 的逆序对. Note: 数组的长度不会超过50,000 不愧是hard模式的题目,虽然已经知道可以 ...

  10. Avito Cool Challenge 2018:D. Maximum Distance (最小生成树)

    题目链接 题意 : 给出一个联通图和一些特殊的点,现在定义cost(u,v)为一条从u到v的路径上面边权的最大值 , 定义dis(u,v) 为从u到v 路径上面cost 的最小值 然后求所有特殊点到其 ...