forked from nehaaggarwal6871/Competitive-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintSubsetSumK
More file actions
57 lines (46 loc) · 986 Bytes
/
printSubsetSumK
File metadata and controls
57 lines (46 loc) · 986 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
52
53
54
55
56
57
// void printSubsetSumToK(int input[], int size, int k) {
// // Write your code here
// }
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
void psubset(int input[],int size,int k,int output[],int m)
{
if(size==0)
{
if(k==0)
{
for(int i=0;i<m;i++)
{
cout<<output[i]<<" ";
}
cout<<endl;
return;
}
else
return;
}
int o1[m+1];
int i;
for(i=0;i<m;i++)
{
o1[i]=output[i];
}
o1[i]=input[0];
psubset(input+1,size-1,k-input[0],o1,m+1);
psubset(input+1,size-1,k,output,m);
}
void printSubsetSumToK(int input[], int size, int k) {
// Write your code here
int m=0;
int output[m];
psubset(input,size,k,output,m);
}
int main() {
int input[1000],length,k;
cin >> length;
for(int i=0; i < length; i++)
cin >> input[i];
cin>>k;
printSubsetSumToK(input, length,k);
}