Home >Backend Development >PHP Tutorial >photoshop cs2 v9.0 green Chinese version PHP solution method of combination algorithm
Topic: Combination Algorithm: There is an array a with N elements. Now we are required to find the number of all combinations containing any element.
Answer: Let’s look at the rules first:
Suppose this array is array(1,2,3,4,5), then M=5;
The possible combinations are:
The number of combinations of 1 number: 5
2 The number of combinations of numbers: 4+3+2+1
The number of combinations of 3 numbers: 3+2+1
The number of combinations of 4 numbers: 2+1
The number of combinations of 5 numbers: 1
It looks familiar, it's a 9*9 multiplication table in reverse order. Except that there are M combinations in the first row, other combinations are processed according to the multiplication table, with 2 FOR statements nested.
Code:
Copy code The code is as follows:
$c = 5;
$a = $c;
for($i=1;$i<=$c;$i++){
for($k=$c-$i;$k>0;$k–){
$a +=$k;
}
}
echo $a;
The above introduces the PHP solution method of the combination algorithm of photoshop cs2 v9.0 green Chinese version, including the content of photoshop cs2 v9.0 green Chinese version. I hope it will be helpful to friends who are interested in PHP tutorials.