-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathSubsequence_with_k_sums.java
More file actions
37 lines (37 loc) · 927 Bytes
/
Copy pathSubsequence_with_k_sums.java
File metadata and controls
37 lines (37 loc) · 927 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
// You are using Java
import java.util.*;
class sample
{
public static void insert(int[] arr,int idx,int s,int k,List<Integer> list,int n)
{
if(idx==n)
{
if(s==k)
{
for(int y:list)
{
System.out.print(y+" ");
}
System.out.println();
}
return;
}
list.add(arr[idx]);
insert(arr,idx+1,s+arr[idx],k,list,n);
list.remove(Integer.valueOf(arr[idx]));
insert(arr,idx+1,s,k,list,n);
}
public static void main(String[] args)
{
Scanner vis=new Scanner(System.in);
int n=vis.nextInt();
int[] arr=new int[n];
for(int i=0;i<n;i++)
{
arr[i]=vis.nextInt();
}
int k=vis.nextInt();
List<Integer> list=new ArrayList<>();
insert(arr,0,0,k,list,n);
}
}