class Solution {
public:
/*
* @param A: an integer array
* @param k: a postive integer <= length(A)
* @param target: an integer
* @return: A list of lists of integer
*/
vector<vector<int>> ans;
vector<vector<int>> kSumII(vector<int> &A, int k, int target) {
// write your code here
vector<int> path;
dfs(A,k,target,0,path);
return ans;
}
void dfs(vector<int> &A,int k,int target,int m,vector<int> path){
if(k==0&&target==0){
ans.push_back(path);
}
if(k<0||target<0) return;
for(int i=m;i<A.size();i++){
vector<int> temp;
temp=path;
temp.push_back(A[i]);
dfs(A,k-1,target-A[i],i+1,temp);
}
}
};