-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ14.java
More file actions
29 lines (24 loc) · 837 Bytes
/
Q14.java
File metadata and controls
29 lines (24 loc) · 837 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
import java.util.ArrayList;
public class Q14 {
public static void main(String[] args) {
int []a = new int[]{ 2 ,3 ,4 ,5};
ArrayList<Integer> b = new ArrayList<> ();
System.out.println (repearsub(a , b , 0 , 7 ,new ArrayList<> ()));
}
private static ArrayList<ArrayList<Integer>> repearsub(int[] a, ArrayList<Integer> b, int idx, int target , ArrayList<ArrayList<Integer>> k ) {
if(idx == a.length ){
if(target == 0){
k.add (new ArrayList<> (b));
return k;
}
return k ;
}
if(target >= a[idx]){
b.add (a[idx]);
repearsub(a , b , idx , target - a[idx], k);
b.remove (b.size () - 1 );
}
repearsub (a , b , idx + 1 , target , k );
return k;
}
}