-
Notifications
You must be signed in to change notification settings - Fork 232
Expand file tree
/
Copy pathPower Set.cpp
More file actions
51 lines (46 loc) · 804 Bytes
/
Copy pathPower Set.cpp
File metadata and controls
51 lines (46 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
Petar 'PetarV' Velickovic
Algorithm: Power Set
*/
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <complex>
using namespace std;
typedef long long lld;
//Metoda koja generise partitivni skup nekog skupa
//Slozenost: O(2^n)
int n;
int skup[100];
bool inSet[100];
void powerSet(int pos)
{
if (pos==n)
{
for (int i=0;i<n;i++) if (inSet[i]) printf("%d ",skup[i]);
printf("\n");
return;
}
inSet[pos] = false;
powerSet(pos+1);
inSet[pos] = true;
powerSet(pos+1);
}
int main()
{
n = 3;
skup[0] = 1;
skup[1] = 2;
skup[2] = 3;
powerSet(0);
return 0;
}