1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <algorithm> 6 #include <vector> 7 #define sc(x) scanf("%d",&(x)) 8 #define sc2(x,y) scanf("%d%d", &(x), &(y)) 9 #define pn printf("%\n") 10 #define PF(x) printf("%d ",x) 11 #define pf(x) printf("%d\n",x) 12 #define CL(x, y) memset(x, y, sizeof(x)) 13 #define FOR(i,b,e) for(int i = b; i <= e; i++) 14 #define max(a, b) (a > b ? a : b) 15 #define ABS(a, b) (a > b ? a - b : b - a) 16 using namespace std; 17 const int MAX = 25; 18 int ans[MAX], used[MAX], n, N = 0; 19 void show(); 20 void DFS(int pos); 21 int main() 22 { 23 sc(n); 24 CL(used, 0); 25 DFS(0); 26 cout << "种类为:" << N << endl; 27 return 0; 28 } 29 void DFS(int pos) 30 { 31 if(pos == n) 32 { 33 show(); 34 N++; 35 return ; 36 } 37 used[pos] = 0; 38 DFS(pos+1); 39 used[pos] = 1; 40 DFS(pos+1); 41 } 42 void show() 43 { 44 int k = 0; 45 FOR(j,0,n-1) 46 // PF(used[j]); 47 if(used[j]) 48 { 49 PF(j+1); 50 k++; 51 } 52 if(!k)printf("空集"); 53 cout << endl; 54 }
时间: 2024-11-12 02:20:17