@shawngao actually,in the dfs function,you don't even need to make a statement to see if (sum[0]==target&&...).

If thinking it over, there is no way to complete the iteration of all matches if there is no solution.

so the dfs can be like:

private boolean dfs(int[] nums, int[] sums, int index, int target) {
if (index == nums.length)
return true;
for (int i = 0; i < 4; i++) {
if(sums[i]+nums[index]<=target){
sums[i] += nums[index];
if (dfs(nums, sums, index + 1, target)) return true;
sums[i] -= nums[index];
}
}
return false;
}