# ArrayList递归不考虑重复元素

``````import java.util.ArrayList;
import java.util.Arrays;

class SumSet {
static void sum_up_recursive(ArrayList<Integer> numbers, int target, ArrayList<Integer> partial) {
int s = 0;
for (int x: partial) s += x;
if (s == target)
System.out.println("sum("+Arrays.toString(partial.toArray())+")="+target);
if (s >= target)
return;
for(int i=0;i<numbers.size();i++) {
ArrayList<Integer> remaining = new ArrayList<Integer>();
int n = numbers.get(i);
ArrayList<Integer> partial_rec = new ArrayList<Integer>(partial);
sum_up_recursive(remaining,target,partial_rec);
}
}
static void sum_up(ArrayList<Integer> numbers, int target) {
sum_up_recursive(numbers,target,new ArrayList<Integer>());
}
public static void main(String args[]) {
Integer[] numbers = {431, 431, 429, 427, 424, 422, 420, 418, 416, 414, 412,
409, 407, 405, 403, 401, 398, 396, 394, 392, 389, 409, 347, 347, 344, 344, 342, 342,
339, 342, 344, 347, 349, 352, 354, 357, 359, 361, 364, 364, 364, 364, 431, 451, 449, 447,
445, 443, 441, 439, 437, 435, 433, 431, 429, 427, 424, 422, 420, 418, 416, 414, 412};
int target = 1590;
sum_up(new ArrayList<Integer>(Arrays.asList(numbers)),target);
}
}
``````