#include<stdio.h> #include<iostream> #include<sstream> #include<queue> #include<map> #include<memory.h> #include <math.h> #include<time.h> #include <stdlib.h> #include <algorithm> using namespace std; #define N 10 int a[N]; int vis[N]; int n, m; void print_subset3(int n,int s) { for(int i=0;i<n;i++) if(s&(1<<i)) printf("%d ",i);
printf(" "); } void print_subtset3(int n) { for(int i=0;i<(1<<n);i++) print_subset3(n, i); } void print_subset2(int n, int cur) { if(cur == n) { for(int i = 0; i < cur; i++) { if(vis[i]) cout << i << " "; } cout << endl; return; } vis[cur] = 1; print_subset2(n, cur + 1); vis[cur] = 0; print_subset2(n, cur + 1); } void print_subset(int n, int* A, int cur) { for(int i = 0; i < cur; i++) cout << " " << A[i]; cout << endl; int s = cur ? A[cur - 1] + 1 : 0; for(int i = s; i < n; i++) { A[cur] = i; print_subset(n, A, cur + 1); } } int main(const int argc, char** argv) { //freopen("d:\1.txt", "r", stdin); //print_subset(3,a,0); //memset(vis, 0, sizeof(vis)); //print_subset2(3, 0); print_subtset3(3); }