Algorithm for optional n in a collection containing M elements

xiaoxiao2021-03-06  22

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 #include #include #include using namespace std; void ssort (int N, int str;]); int main () {int I, N, J = 0, M, COUNT, TEMP, I_BEGIN = 1, I_END, M, FLAG = 0; Vector IINT; STRING SS; COUT << "How Many Elements do you want the set include:" ; Cin >> m;

COUT << "please input" << m << "Elements:"; int * str = new int [m]; vector :: item vi; for (i = 0; i > SS; IINT.PUSH_BACK (SS);

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 = STR [M]) FLAG = 1; if (flag) Continue; COUT << "<"; for (j = 0; j

}

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 1 && count

EXAMPLE:

转载请注明原文地址:https://www.9cbs.com/read-42607.html

New Post(0)