zoukankan      html  css  js  c++  java
  • BJFU 1551 ——delightful world——————【暴搜】

    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
    ",res);
        }
        return 0;
    }
    

      

  • 相关阅读:
    C 位与运算
    C语言指针总结(转载)
    C# webApi 之Ajax跨域(带头部参数)
    VS2017 .NET Core IIS 部署
    .Net Core 视图组件新玩法(ViewComponent视图组件族)
    EveryNote使用说明,好用的文件备注搜索工具
    【免费开源】Asp.net Core 开发的后台框架(权限介绍)
    Asp.net Core 一个实用的自定义TagHelpers
    c#简单代码:用获得的cookie访问目标网站
    Could not load file or assembly ‘xxx’ or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.
  • 原文地址:https://www.cnblogs.com/chengsheng/p/5435625.html
Copyright © 2011-2022 走看看