Permutation and combination formula/Permutation and combination calculation formula Formula P refers to permutation, taking R elements from N elements to arrange them. Formula C refers to combination. R elements are taken from N elements without arrangement. But in PHP we can write it in N ways, but the performance of each writing method will be different. Let’s take a look below. .
The requirements are as follows:
Find all possible combinations of the specified length in the array without duplication.
Method 1:
The code is as follows | |
function getCombinationToString($arr,$m){ $temp_list2 = getCombinationToString($arr, $m); var_dump($t); |
执行时间:238ms。
方法二:
代码如下 | |||||
function getCombinAryByNum( $arr, $num,$t=array()) {
$arr = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18);
var_dump($ss); |
PHP中排列组合及性能对比 排列组合公式/排列组合计算公式公式P是指排列,从N个元素取R个进行排列。 公式C是指组合,从N个元素取R个,不进行...