PHP Solution for combined Algorithms

Source: Internet
Author: User

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:
Copy codeThe Code is as follows:
$ C = 5;
$ A = $ c;
For ($ I = 1; $ I <= $ c; $ I ++ ){
For ($ k = $ c-$ I; $ k> 0; $ k -){
$ A + = $ k;
}
}
Echo $;

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.