Problem: An optional combination of n is optionally selected from the collection containing M elements.
Idea: Use the M-Bao's array to represent
The source program is as follows (tested in C-Free 3.5)
/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------- Author: rainfly (proud) 3-25-05 Describe: An algorithm for the power set is also from M elements Optional N of the algorithm. If you have other ideas, please email me: yan_diao266071@163.com test in c-free 3.5 ------------------- -------------------------------------------------- - * /
#include
COUT << "please input" << m << "Elements:"; int * str = new int [m]; vector
COUT << Endl; cout << "The Elments of this set is:"; for (vi = int.begin (); vi! = int.end (); vi ) cout << * vi << "; cout << endl; / * Output n Elements * / cout << "please input a number (0 ~" << m << "):"; cin >> n; // insure the scope of i for (i = 0 i
}
Delete [] STR;
Return 0;}
Void ssort (int N, int STR [], int M, int N) {INT i = 0, count = 0, TEMP; while (n> = 0) {IF (n EXAMPLE: