public static ArrayList<Integer> subset(int arr[],int ci,int n)
{
if(c1==n)
{
ArrayList<Integer> base = new ArrayList<Integer>();
base.add(0);
return base;
}
int first = a[ci];
ArrayList<Integer> result = new ArrayList<Integer>();
ArrayList<Integer> sol = new ArrayList<Integer>();
result = subset(arr,ci+1);
for(int e:result){
sol = e;
sol = first + e;
}
return sol;
}
public static void main(String args[]) {
ArrayList<Integer> output = new ArrayList<Integer>();
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int n = sc.nextInt();
int arr = new int[n];
for(int i=0;i<n;i++)
{
arr[i] = sc.nextInt();
}
for(int i=0;i<t;i++)
{
output = subset(arr,0,n);
output.remove(0);
if(output.contains(0))
System.out.println("YES");
else
System.out.println("NO");
}
package testrecursion;[quote=“affanahmed, post:1, topic:32394, full:true”]
public class Main {
public static ArrayList<Integer> subset(int arr[],int ci,int n)
{
if(c1==n)
{
ArrayList<Integer> base = new ArrayList<Integer>();
base.add(0);
return base;
}
int first = a[ci];
ArrayList<Integer> result = new ArrayList<Integer>();
ArrayList<Integer> sol = new ArrayList<Integer>();
result = subset(arr,ci+1);
for(int e:result){
sol = e;
sol = first + e;
}
return sol;
}
public static void main(String args[]) {
ArrayList<Integer> output = new ArrayList<Integer>();
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int n = sc.nextInt();
int arr = new int[n];
for(int i=0;i<n;i++)
{
arr[i] = sc.nextInt();
}
for(int i=0;i<t;i++)
{
output = subset(arr,0,n);
output.remove(0);
if(output.contains(0))
System.out.println("YES");
else
System.out.println("NO");
}
}
[/quote]
i tried this code in eclipse fine but your suggestions for logical improvement will help a lot.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.