I am not able to solve the problem. I looked into the solution but i am not able to still understand.
//Solution Code
import java.util.Scanner;
public class Main {
public static boolean subsetSumEasy(int[] v, int i, int sum, boolean included) {
if (i == v.length) {
return (sum == 0 && included);
}
boolean inc = subsetSumEasy(v, i + 1, sum + v[i], true);
boolean exc = subsetSumEasy(v, i + 1, sum, included);
return inc || exc;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int testCases = sc.nextInt();
while (testCases-- > 0) {
int n = sc.nextInt();
int[] v = new int[n];
for (int i = 0; i < n; i++) {
v[i] = sc.nextInt();
}
if (subsetSumEasy(v, 0, 0, false)) {
System.out.println("Yes");
} else {
System.out.println("No");
}
}
Problem Statement:
Can you please make a pictorial diagram as Chitra Maam makes in the other cases.
With the given input
1
4
1 3 2 -3
In the solution provided when are we are talking about the case when we are adding subset { 3,2 } { 2,-3 } and checking for zero sum.