Algorithm for combinatorial permutation of PHP majority group

Source: Internet
Author: User
Simulate four arrays:
$list [' a '] = array (All-in-all);
$list [' b '] = array (4,5,6);
$list [' c '] = array (7,8,9);

The requirements are combined into this: 14,15,16,17,18,19,24,25,26,27,28,29,34,35,36,37,38,39,47,48,49,57,58,59,67,68,69

Find an algorithm


Reply to discussion (solution)

See a section of code online:

 Getsulie ($list, $v, 1);            }} function Getsulie ($list, $content, $deep) {$i = 0;            if ($deep >count ($list)) {return;                        } foreach ($list as $k = + $v) {if ($i = = $deep) {foreach ($list [$k] as $VV) {                        $VV = $content. $vv; if ($deep ==count ($list)-1) {echo $vv. "
"; }else {$this->getsulie ($list, $VV, $deep + 1); }} break; } $i + +; } return; }} $s = new sufa (); $s->main (); ?>


But it's not like this.

Recursion is not a good use, ask the big God pointing

$list [' a '] = Array (n/a), $list [' b '] = Array (4,5,6), $list [' c '] = array (7,8,9); foreach ($list as $key + = $row) {  uns ET ($list [$key]);  foreach ($row as $col) {    foreach ($list as $r)      foreach ($r as $v) $res [] = $col. $v;  }} echo Join (', ', $res);
14,15,16,17,18,19,24,25,26,27,28,29,34,35,36,37,38,39,47,48,49,57,58,59,67,68,69

$list [' a '] = Array (n/a), $list [' b '] = Array (4,5,6), $list [' c '] = array (7,8,9); foreach ($list as $key + = $row) {  uns ET ($list [$key]);  foreach ($row as $col) {    foreach ($list as $r)      foreach ($r as $v) $res [] = $col. $v;  }} echo Join (', ', $res);
14,15,16,17,18,19,24,25,26,27,28,29,34,35,36,37,38,39,47,48,49,57,58,59,67,68,69




Positive solution, which requires 3 number combinations, and how the amount of implementation, such as

$list [' a '] = Array (7,8,9), $list [' b '] = Array (4,5,6), $list [' c '] = Array (10,11,12), $list [' d '] = array


Ultimately, you need to get:
147,148,149,157,158,159,167,168,169,247,248,249,257,258,259,267,268,269,347,348,349,357,358,359,367,368,369

$list [' a '] = Array (n/a), $list [' b '] = Array (4,5,6), $list [' c '] = array (7,8,9); foreach ($list as $key + = $row) {  uns ET ($list [$key]);  foreach ($row as $col) {    foreach ($list as $r)      foreach ($r as $v) $res [] = $col. $v;  }} echo Join (', ', $res);
14,15,16,17,18,19,24,25,26,27,28,29,34,35,36,37,38,39,47,48,49,57,58,59,67,68,69





It was wrong and wrote an array,
$list [' a '] = Array (7,8,9), $list [' b '] = array (4,5,6); $list [' c '] = array


Ultimately, you need to get:
147,148,149,157,158,159,167,168,169,247,248,249,257,258,259,267,268,269,347,348,349,357,358,359,367,368,369

I thought you were working on a problem you need to solve, no chengxiang you're studying algorithms.
From an algorithmic point of view, your two topics should be: Cartesian product for the results of combination (C (m,n)) of the original data
The code is out of the way, you can find multiple versions in the elite area.

I thought you were working on a problem you need to solve, no chengxiang you're studying algorithms.
From an algorithmic point of view, your two topics should be: Cartesian product for the results of combination (C (m,n)) of the original data
The code is out of the way, you can find multiple versions in the elite area.



Thank you
  • Related Article

    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.