I am not getting any idea
Can you please tell how to do this question
hello @haseebshaik00 in this question you have to apply backtrack and check if the sum is greater then you have to backtrack and mark that numbers that they cannot give you the answer and you have to track again if there is any possible arrangement .
here for your reference i am attaching the code :
tell me if you dont understand anyline please ask here .
Happy Learning !!
int prev=-1;
for(int i=s;i<=e;i++){
if(a[i]!=prev){
arr[arri]=a[i];
prev=a[i];
sumitup(a,arr,t-a[i],arri+1,e,i+1);
}
didn’t understand this part of the code and where are we using backtracking?
and in the question it is clearly written "Note that each number in the array may only be used once in the combination " then how come in the output it displays 1 1 6???
@haseebshaik00 see the input .
in input we have 2 ones in the input and in this way we have to print the result .
and in the lines which you mentioned above we are marking the prev and if the prev is the marked then we cannot take the number .
but in the above example we have 2 one’s thats why we have to can print both the 1’s .
if you still have any doubt please ask here .
Happy Learning !!
where are we using backtracking?
@haseebshaik0 backtrack doesn’t only mean that we have to make the matrix and mark the positions as 0 and 1 but you have to think differently .
like in this way we have to mark numbers and check if that number is not been used then we can use this number and if the other number is used then we cannot take that number .
here we have to use in this way .
please tell me if you still have any doubt ?
Happy Learning !!
I still can’t understand in the question it is clearly written "Note that each number in the array may only be used once in the combination " then how come in the output it displays 1 1 6???
i got it thank you!!!1
hello @haseebshaik00 it is because that we have 1 two times in the input and every element occurence is unique .
if you feel that your doubt is cleared please mark this doubt as resolved.
Happy Learning !!