Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 如何制作这种模式发现算法?_Algorithm_Math_Statistics_Pattern Matching - Fatal编程技术网

Algorithm 如何制作这种模式发现算法?

Algorithm 如何制作这种模式发现算法?,algorithm,math,statistics,pattern-matching,Algorithm,Math,Statistics,Pattern Matching,我有一个矩阵,我需要在这个矩阵中找到一个模式。 矩阵为: 1 0 0 1 1 1 0 0 0 1 0 0 0 1 1 0 1 0 0 1 0 1 1 1 0 0 0 1 0 1 1 0 1 0 0 1 1 0 1 0 1 1 1 0 0 0 1 1 0 1 0 1 0 0 1 1 0 1 0 1 1 1 1 0 0 0 1 0 0 1 1 0 0 1 0 1 1 1 0 1 规则: 我们从每行中选择一个数字 第二行的下一个choosen编号必须与前一行相反 由1和2规则选择的数字位置必须是精确

我有一个矩阵,我需要在这个矩阵中找到一个模式。 矩阵为:

1 0 0 1 1 1 0 0 0 1
0 0 0 1 1 0 1 0 0 1
0 1 1 1 0 0 0 1 0 1
1 0 1 0 0 1 1 0 1 0
1 1 1 0 0 0 1 1 0 1
0 1 0 0 1 1 0 1 0 1
1 1 1 0 0 0 1 0 0 1
1 0 0 1 0 1 1 1 0 1
规则:

  • 我们从每行中选择一个数字
  • 第二行的下一个choosen编号必须与前一行相反
  • 由1和2规则选择的数字位置必须是精确的模式
  • 因此,问题是:

    找到符合这3条规则的最佳模式。 矩阵中的示例如下所示:

  • 选择了一个数字:0(2)//在“()”中的内容表示值的位置。。位置从行的1到10开始
  • 1(4)
  • 对于位置2和4,模式必须支持矩阵其余部分的规则1和2
  • 所以我们在第三排进一步检查第二个位置:1。我们去第四排,我们检查第四个位置:0。似乎尊重规则。第二排和第四排的数字是相反的,所以我们继续:第五排,第二排:,依此类推,但你会看到第七排第二排:1和第八排第四排:1;所以位置2-4的模式不好

    我怎样才能根据这些规则制定算法?

    也许这会有所帮助(出于对您问题的评论)。这是C++的一种答案。此答案假定0始终是您选择的数字,但您可以轻松编辑此值以允许1位于第一位

    int firstPos, secondPos;
    
    for(int i = 0; i < 10; ++i)
        if(matrix[0][i] == 0)
            firstPos = i;
    
    for(int i = 0; i < 10; ++i)
        if(matrix[0][i] == 1)
            secondPos= i;
    
    bool success = true;
    
    for(int i = 0; i < 10/2; ++i)
        if(matrix[2*i][firstPos] == matrix[2*i][secondPos])
            success == false;
    
    if(success)
        cout << "success" << endl;
    else 
        cout << "failure" << endl;
    
    int-firstPos,secondPos;
    对于(int i=0;i<10;++i)
    if(矩阵[0][i]==0)
    firstPos=i;
    对于(int i=0;i<10;++i)
    if(矩阵[0][i]==1)
    secondPos=i;
    布尔成功=真;
    对于(int i=0;i<10/2;++i)
    if(矩阵[2*i][firstPos]==矩阵[2*i][secondPos])
    成功==错误;
    如果(成功)
    
    cout我将通过第一项(F)的索引和第二项(S)的索引来定义模式。我还假设索引以0开头(而不是像您的示例中的1)。F和S都可以取0到9之间的值。解决办法很简单。有一个从0到9运行F和S的双嵌套循环,在第三个最内层循环中,只需验证当前F和S是否形成一个模式。

    您已经“创建”了算法。我不明白你为什么不用你最喜欢的编程语言编写你的指令列表并继续下去。如果您陷入困境,或者您认为您的算法是次优的(在某种意义上),请再次发布您的代码,我们将提供一些帮助。