[url=][/url]
#include<stdio.h>#include<stdlib.h>#include<string.h>#define MAXCANDIDATES 100bool is_a_solution(int *a, int k, int n) { return k == n;}void process_solution(int* a, int k, int n) { int i; printf("{"); for(i = 1; i <= k; ++i) { if (a == true) printf("%d", i); } printf("}\n");}void construct_candidate(int a[], int k, int n, int c[], int *ncandidates) { c[0] = false; c[1] = true; *ncandidates = 2;}void backtrack(int* a, int k, int n) { int c[MAXCANDIDATES]; int ncandidates; int i; if (is_a_solution(a, k, n)) { process_solution(a, k ,n); } else { k = k + 1; construct_candidate(a, k, n, c, &ncandidates); for (i = 0; i < ncandidates; i++) { a[k] = c; backtrack(a, k, n); } }}void generate_subsets(int n) { int *a = (int*)malloc(sizeof(int)*n); memset(a, 0, sizeof(int) * n); for(int i = 0; i < n; i++) a= i + 1; backtrack(a, 0, n);}int main(){ generate_subsets(3); return 0;}