For a combination, such as C (), we can use the formula to find the number of the numbers, but how can we express these numbers?
Code:
<SPAN style = "FONT-SIZE: 18px"> # include <iostream> # include <stdio. h> # define MAXN 100 using namespace std; int a [MAXN]; int count = 0; void assem (int m, int k) {int I, j; for (I = m; I> = k; I --) {a [k] = I; if (k> 1) assem (I-1, k-1 ); else {count ++;/* display the number of permutation for (j = a [0]; j> 0; j --) {cout <a [j] <";}cout <endl; */}}} int main () {int m, r; cout <"m ="; cin> m; cout <"r ="; cin> r; a [0] = r; assem (m, r ); cout <count <endl; return 0 ;}</SPAN> # include <iostream> # include <stdio. h> # define MAXN 100 using namespace std; int a [MAXN]; int count = 0; void assem (int m, int k) {int I, j; for (I = m; I> = k; I --) {a [k] = I; if (k> 1) assem (I-1, k-1 ); else {count ++;/* display the number of permutation for (j = a [0]; j> 0; j --) {cout <a [j] <";}cout <endl; */}}} int main () {int m, r; cout <"m ="; cin> m; cout <"r ="; cin> r; a [0] = r; assem (m, r ); cout <count <endl; return 0 ;}
For example, if we require C (), we should first take one number from 16 numbers [to C )], then take a number from the remaining 15 numbers [to C ()], and finally take a number from the remaining 14 numbers [to C. Therefore, this process is easily implemented through recursion.