Is there a way to solve the problem Sum It Up using arrays only? I could think of this much, can anyone modify it
Help needed in Sum It Up
@Parikalp10 correct way
- Sort the array(non-decreasing).
- First remove all the duplicates from array.
- Then use recursion and backtracking to solve the problem.
-
- If at any time sub-problem sum == 0 then add that array to the result (vector of vectors).
-
- Else if sum if negative then ignore that sub-problem.
-
- Else insert the present array in that index to the current vector and call the function with sum = sum-ar[index] and index = index, then pop that element from current index (backtrack) and call the function with sum = sum and index = index+1
-
try implementing it if any problem i will refer you the editorial code
why should we remove the duplicates? and this method is given in the editorial, that is why i asked over here, if you could modify my code, otherwise i would have copied the editorial code, but i did not understand that
@Parikalp10 duplicates are not allowed as per the question , and what is your doubt in this.
dry run the code for a small example you will understand it then
i found this code, can you please explain this?
My problem with the solution provided in the editorial is that I do not have much knowledge of vectors yet so i just want to solve it using arrays
@Parikalp10 ok here a simple recursive include exclude code without vectors
map is only used to check whether there is duplicate or not