Photoshop CS2 v9.0 Green Chinese version of the combination algorithm PHP solution

Source: Internet
Author: User
Title: Combinatorial algorithm: There is an array a with n elements, and now it is required to find out the number of all combinations containing arbitrary elements.
Answer: Look at the law first:
Suppose that this array is m=5 as array (1,2,3,4,5);
The combinations that may appear are:
Number of combinations of 1 numbers: 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
Number of combinations of 5 numbers: 1
It looks familiar, it is a 9*9 multiplication table in reverse order. Except that the first line has m combinations, the other combinations are handled by the multiplication table, and 2 for statements are nested.
Code:

Copy the Code code 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 describes the Photoshop CS2 v9.0 Green Chinese version of the combination algorithm PHP solution, including the Photoshop CS2 v9.0 Green Chinese version of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.