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:
Assume this array is array(1,2,3,4,5) then M=5;
The possible combinations are:
1 number Number of combinations: 5
Number of combinations of 2 numbers: 4+3+2+1
Number of combinations of 3 numbers: 3+2+1
Number of combinations of 4 numbers: 2+1
The number of combinations of 5 numbers: 1
It looks familiar, it is a 9*9 multiplication table in reverse order. Except for the M combinations in the first row, other combinations are processed according to the multiplication table, and the two FOR statements are nested
Code: