[N subset of m element sets], subset of m element sets
/* N subset of m elements: Assume that a set has m elements and n elements are retrieved from the set, what are the possible subsets of the n elements? Solution: Assume that there are five element set points and the possible subsets of the three elements are as follows: {1 2 3}, {1 2 4}, {1 2 5}, {1 3 4}, {1 3 5}, {1 4 5}, {2 3 4 4 }, {2 3 5}, {2 4 5}, and {3 4 5} subsets are ordered in alphabetical order, in this way, we can observe some rules: If the rightmost element is smaller than m, we will continue to add 1 as the code table. If the right one has reached the maximum value, after the position where the value of 1 is shifted to the left, the elements on the right must be adjusted to the descending order. Therefore, the key point is that the position must be incremented by 1, add 1 to the rightmost position? Or other locations? When writing a program, you can use a variable positon to record the position where the value of position is added. The initial value of position is set to n-1 because the array is used, the rightmost index value is the largest n-1. If the value at the position is smaller than m, 1 is continuously added. If the value is greater than m, the position value is reduced by 1, that is, move the position to the left. Because the right element is adjusted after the Left shift, we must check whether the rightmost element is smaller than m. If yes, the position is adjusted back to n-1, if not, positon remains unchanged. */# Include <stdio. h> # include <stdlib. h ># define MAX 20int main (void) {int set [MAX]; int m, n, position; int I; printf ("Number of input sets :"); scanf ("% d", & m); printf ("input extract element n:"); scanf ("% d", & n); for (I = 0; I <n; I ++) {set [I] = I + 1 ;}for (I = 0; I <n; I ++) {printf ("% d", set [I]);} putchar ('\ n'); position = n-1; while (1) {if (set [n-1] = m) {position --;} else {position = n-1;} set [position] ++; for (I = position + 1; I <n; I ++) {set [I] = set [I-1] + 1 ;}for (I = 0; I <n; I ++) {printf ("% d", set [I]);} putchar ('\ n '); if (set [0]> = m-n + 1) {break ;}} return 0 ;}