php - 使用php构建概率树?

标签 php tree probability

<分区>

Possible Duplicate:
Permutations - all possible sets of numbers

我有一个包含选项列表的数组, 每个选项都是唯一的,不能重复。

我想使用这些选项构建概率树:

$options = array('1','2','3','4','A','E','I','O');

所以一个有效行可以是 1-2-E-3-O-I-4-A

我该怎么做? (或者至少给我指出正确的方向!)

最佳答案

<?php

function pc_permute($items, $perms = array( )) {
    if (empty($items)) { 
        print join('-', $perms) . "<br />";
    }  else {
        for ($i = count($items) - 1; $i >= 0; --$i) {
            $newitems = $items;
            $newperms = $perms;
            list($foo) = array_splice($newitems, $i, 1);
            array_unshift($newperms, $foo);
            pc_permute($newitems, $newperms);
        }
    }
}

$options = array( '1','2','3','4','A','E','I','O' );
$mass = pc_permute( $options );

?>

关于php - 使用php构建概率树?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12582692/

相关文章:

tree - graphviz,如何将节点放置在图像上

python - 子树之前有多少片叶子?

algorithm - 水库采样了解概率

php - 语法错误或访问冲突 : 1064

php - 如何显示多个搜索结果

php - this 在 C++、PHP 和其他语言中的用法

python - 我怎样才能找到树中的最小值?

python - 在 Python 中定义白噪声过程

r - 累积概率为50%时计算 "x"

php - 从我的数据库中选择多个 STEAMID