[Algorithm] an algorithm for sorting and combination

Source: Internet
Author: User
[Algorithm] The following is an algorithm for finding a permutation and combination.
From 0 ~ 9, ~ Z: three numbers are randomly selected from the 36 characters to calculate the number of permutation and combination methods.
Please advise


Reply to discussion (solution)

36*36*36 = 46656

36*36*36

I wrote it myself.

/*** Permutation and combination algorithm * C ($ n, $ m) * $ n number of elements * $ m number of elements retrieved from $ n * $ total number of num combinations */function get_combination ($ n, $ m) {if (is_int ($ n) & is_int ($ m) & ($ m <= $ n) {$ a = 1; // initialize for ($ I = 1; $ I <= $ m; $ I ++) {$ a = $ n * $ a; $ B = 1 * $ I; $ n -- ;}$ num = $ a/$ B; return $ num ;}}

Combination formula: c (n, m) = p (n, m)/m! = N! /(N-m )! * M !)
Do you think you are correct?

Combination formula: c (n, m) = p (n, m)/m! = N! /(N-m )! * M !)
Do you think you are correct?


You can try

36*35*34

The sum is 7140.
Half less than you


Combination formula: c (n, m) = p (n, m)/m! = N! /(N-m )! * M !)
Do you think you are correct?


You can try

Echo get_combination (3, 3 );
Output 2
Why not?

Echo get_combination (3, 3 );
Output 2
Why not?


Well, I saw it again.
The formula you wrote is also incorrect.
If you follow your formula
We propose two numbers from two numbers to arrange them equal to 1.

Pair
From the two numbers, we propose that the combination of two numbers is 1.
Arrangement is 2
P (n, m) = n (n-1) (n-2 )...... (N-m + 1) = n! /(N-m )! (Rule 0! = 1 ).

The three numbers below can be the same.

For example, extract two random numbers from an array (1, 2) to combine them.
11
22
12
21

Pair
From the two numbers, we propose that the combination of two numbers is 1.
Arrangement is 2
P (n, m) = n (n-1) (n-2 )...... (N-m + 1) = n! /(N-m )! (Rule 0! = 1 ).



Okay, you have moved yourself in.
N ^ m is OK
Thank you.
I 've been struggling to arrange and combine

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.