photoshop cs2 v9.0 green Chinese version PHP solution method of combination algorithm

WBOY
Release: 2016-07-29 08:47:57
Original
988 people have browsed it

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.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!