An explanation of the implementation process of PHP simple permutation and combination algorithm

Source: Internet
Author: User
This article mainly introduces the simple permutation and combination algorithm of PHP implementation, combined with specific application examples to analyze the implementation of the permutation algorithm and the use of skills, the need for friends can refer to the next

This paper introduces the application of simple permutation and combination algorithm of PHP implementation. Share to everyone for your reference, as follows:

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] =&gt ; 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)) 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.