PHP solution for combined algorithms. Question: composite algorithm: there is an array a with N elements. now we need to find the number of all combinations containing any element. Answer: Let's take a look at the rule first. suppose this array is array (1 question: composite algorithm: there is an array a with N elements. now we need to find the number of all combinations containing any element.
Answer: check the rule first:
Assume that the array is array (1, 2, 3, 4, 5), then M = 5;
Possible combinations:
Number of combinations of one number: 5
Number of combinations of two numbers: 4 + 3 + 2 + 1
Number of combinations of the three numbers: 3 + 2 + 1
Number of combinations of four numbers: 2 + 1
Number of combinations of five numbers: 1
Well, it's a 9*9 multiplication table in reverse order. Except for m combinations in the first row, other combinations are processed by multiplication tables, and only two FOR statements are nested.
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 $;
The number of combinations containing any element. Answer: Let's look at the rule first. suppose this array is array (1...