I wrote a recursive subsequent assembly program today.

zhaozj2021-02-16  65

It turned out that the algorithm is too weak, there is no idea.

// generate all subssets of n elements

#include

// define globalsint x [20], // subset vector n; // number of elements

Void subsets (INT i) {// Output All Subsets of X [1: N]. // ONLY X [i: n] to be change. if (i == n) {// x [n] can be 0 OR 1 // Output Subset without Element N x [n] = 0; for (int J = 1; j <= n; j ) cout << x [j] << "; cout << endl; // output Subset with element n x [n] = 1; for (j = 1; j <= n; j ) cout << x [j] << "; cout << endl; return;} // Leave Element i Out X [i] = 0; // generate all subssets with i out subssets (i 1); // Put Element I Into Subset x [i] = 1; // generate all subssets with i incruded subsets (i 1) } Void main (void) {n = 4; subsets (1);

This is required to strengthen exercise

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

New Post(0)