Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Result {
- public static boolean helper(int idx, List<Integer> s, List<Boolean> slate, int sumGroup1, int sumGroup2, List<Boolean> results){
- if(idx == s.size()){ // base case
- if(sumGroup1 == sumGroup2 && slate.stream().distinct().count() > 1){
- results.addAll(slate);
- return true;
- }
- }
- else{ // recursive case
- // include in group 1
- slate.add(true);
- if(helper(idx+1, s, slate, sumGroup1+s.get(idx), sumGroup2, results)){
- return true;
- }
- slate.remove(slate.size()-1);
- // exclude from group 1 / include in group 2
- slate.add(false);
- if(helper(idx+1, s, slate, sumGroup1, sumGroup2+s.get(idx), results)){
- return true;
- }
- slate.remove(slate.size()-1);
- }
- return false;
- }
- public static List<Boolean> equalSubSetSumPartition(List<Integer> s) {
- List<Boolean> results = new ArrayList<>();
- Boolean[] dp = new Boolean[s.size()+1];
- helper(0, s, new ArrayList<>(), 0, 0, results);
- // System.out.println(results);
- return results;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement