-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallpartition.cpp
More file actions
45 lines (42 loc) · 801 Bytes
/
allpartition.cpp
File metadata and controls
45 lines (42 loc) · 801 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
#include <bits/stdc++.h>
using namespace std;
void print(string t)
{
cout<<t<<"\n";
}
void partition(int *a,int n,string t="",int pos=0)
{
if(pos==n)//if a partition is ready print it
{
print(t);
return;
}
for(int i=pos;i<n;i++)//recurring at every position of array
{
string p;
for(int k=pos;k<=i;k++)//including elements in partition starting at current position
{
p+=to_string(a[k]);
p+=" ";
}
partition(a,n,t+"{"+p+"}",i+1);
}
}
signed main()
{
int *a,n;
cout<<"n?"<<"\n";
cin>>n;
a=new int[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<n;i++)//printing original array
{
cout<<a[i]<<" ";
}
cout<<"\n";
partition(a,n);//function for partition
return 0;
}