public void dfs(int nums[], int k, int begin, int target) {
        // base class
        if (k == 2) {
            HashSet<Integer> set = new HashSet<>();
            set.add(nums[begin]);
            for (int i = begin + 1; i < nums.length; ++i) {
                int remain = target - nums[i];
                if (set.contains(remain)) {
                    total += 1;
                }
                set.add(nums[i]);
            }
            return;
        }
        for (int i = begin; i <= nums.length - k; ++i) {
            int val = nums[i];
            if (val >= target)
                return;
            dfs(nums, k - 1, i + 1, target - val);
        }
    }