Plz check i have done this code in this way

https://ide.codingblocks.com/s/305661 plz find whats the error

@kingshuk441 removed the loop and n=4

i want to ask why we cant use loop as for each element we choose to select,or not to select and this we have to this for all elements of array as we have done in min. coins change problem

@kingshuk441 in this we are already iterating through recursion on each element and including it excluding it so whats the point of the loop its like your are iterating on every element and then for that iterating again on every one it makes no sense.
min coins and knapsack are very different problems

can u plz tell whats the difference between both question i am getting confused

@kingshuk441 can you send the question link as there are many types of coin problems


see in this they have used loop for number of options

@kingshuk441 btw in this webinar both questions are there with explanation by prateek bhaiya
(knapsack in the end and coins problems somewhere in between)

@kingshuk441 yes the same question is there in the video i provided refer that

@kingshuk441 also in min coins you can take any coin any no of times but in knapsack only two options include and exclude

yes thats why we have same choices for each state in coin change but also in knapsack we have 2 options(include and exclude) for each item in array

so why we cant use loop .in loop we include and exclude ith item of array and then in every recursive call we decrease value of n so that for next call the ith item gets unavailable

@kingshuk441 in coins you can use anyone any no of times but in knapsack if you include you can do that only once for an item.

but i have removed the element and started the loop afterwards why it is not working

plz check my code once

@kingshuk441 maanlo tumne pehle koi element leliya like nth tha 100 aur aage iterate karde 50 leliya phir tum n-1 pe jaaoge same process karoge aur 50 dobaara le loge toh ye galat hogaya duplicates aarahe hai

sir aap plz brief me ek baar iska recursive tree bana do plz

jaha pe galti ayegi plz

@kingshuk441 2d dp hai recursion tree nahi banpaayega but aise socho
tum har element be jaake phir aage ke saare pe iterate kar rahe ho koi sense nahi ban raha iska har pe ek baar hi jaana hai
apne code mein hi dekhlo 180 ans aaraha hai matlab kahin toh duplicate aarahe hai varna 180 not possible

true matlab ye tab kar sakte jab duplicates allowed ho