This paper mainly introduces the simple permutation combination algorithm of PHP implementation, combined with specific application examples to analyze the implementation and use of the permutation algorithm, the need for friends can refer to, hope to help everyone.
First, the question:
Give you a 40 catty of watermelon, to 3 people, how many kinds of sub-method?
Second, PHP implementation code:
<?PHP$AA = Range (1,40), $BB = Array (), foreach ($aa as $k = = $val) {foreach ($aa as $v ) {foreach ($aa as $vl ) {
$sum = $val + $v + $vl; if ($sum = =) { $bb [$k][0] = $val; $BB [$k][1] = $v; $BB [$k][2] = $VL; }}} Echo ' <pre> ';p rint_r ($BB); exit; >
The results of the operation are as follows:
Array ([0] = = Array ([0] = 1 [1] = [2] = 1) [1] = = Array ([0] = = 2 [1] = [2] = 1) [2] = = Array ([0] = 3 [1] = [2] = 1) [3] = = Array ([0] = 4 [1] = + [2] = 1) [4] = = Array ([0] = 5 [1] [2] = 1) [5] = = Array ([0] = 6 [1] = [2] = 1) [6] =& Gt Array ([0] = 7 [1] = [2] = 1) [7] = = Array ([0] = 8 [1] = = [2] = 1) [8] = = Array ([0] = 9 [1] = + [2] = 1) [9] = = Array ([0] = [1] = [2] = 1) [Ten] = = Array ([0] = [1] = 28 [2] = 1) [One] = Array ([0] = [1] = [2] = 1) [] = = Array ([0] = 13 [1] [+] = [2] = 1) [+] = Array ([0] = [1] = [2] = 1) [+] = Array ([0] = [1] = [2] = 1) [+] = Array ([0] = 16 [1] [+] [2] = 1) [+] = Array ([0] = [1] = [2] = 1) [+] = Array ([0] = [1] = [2] = 1) [+] = Array ([0] = 19 [1] [2] = 1) [+]/= Array ([0] = [1] = [2] = 1) [ [0] = [1] = [2] = 1) [+] = Array ([0] = 22 [1] [+] = [2] = 1) [+]/= Array ([0] = [1] = [2] = 1) [2 3] = = Array ([0] = [1] = + [2] = 1) [[0] = = Array ([+] = 25 [1] = 14 [2]+ 1) [+] = Array ([0] = [1] = [2] = 1) [+] = = Array ( [0] = [1] = [2] = 1) [+] = Array ([0] = [1] = 11 [2] = > 1) [+] = Array ([0] = [1] = [2] = 1) [+] = + Array ([ 0] = [1] = 9 [2] = 1) [+] = = Array ([0] = [1] = 8 [2] => ; 1) [+] = = Array ([0] = + [1] = 7 [2] = 1) [+] = = Array ([0] =&G T [1] = 6 [2] = 1) [[[0] = [1] = +/-5 [2] = 1) [+] = Array ([0] = [1] = 4 [2] = 1) [+] = Array ([0] = 36 [1] = 3 [2] = 1) [+] = = Array ([0] = Notoginseng [1] = 2 [2] = 1) [37 ] = = Array ( [0] = [1] = 1 [2] = 1))