public bool solveR(int[] arr, int n) { if (n == 0) { return(false); } int sum = 0; for (int i = 0; i < n; i++) { sum += arr[i]; } // If sum is odd, there cannot be two subsets with equal sum if (sum % 2 != 0) { return(false); } //Find if there is subset with sum equal to half of total sum SubsetSum subsetSum = new SubsetSum(); return(subsetSum.solveR(arr, n, sum / 2)); }
public bool solveBottomUp(int[] set, int n) { int sum = 0; for (int i = 0; i < n; i++) { sum += set[i]; } // If sum is odd, there cannot be two subsets with equal sum if (sum % 2 != 0) { return(false); } SubsetSum ss = new SubsetSum(); return(ss.solveBottomUp(set, n, sum / 2)); }