public static void depthFirstSearch(int sum, int target, int pos, int[] num,
            ArrayList<Integer> tmp, ArrayList<ArrayList<Integer>> res) {
        if (sum == target) {
            res.add(new ArrayList<Integer>(tmp));
        } else {
            for (int i = pos; i < num.length;) {
                if (sum + num[i] <= target) {
                    tmp.add(num[i]);
                    depthFirstSearch(sum + num[i], target, i + 1, num, tmp, res);
                    tmp.remove(tmp.size() - 1);
                }

                int j = i + 1;
                while (j < num.length && num[j] == num[i]) {
                    j++;
                }

                i = j;
            }
        }
    }