Knapsack question

here profit = Pn-1 + profit(n-1,c-Wn-1)
profit(n-2,c-Wn-2) nahi ana chahiye kyunki Pn-1 humne already include kar liya and vo next time bhi hum n-1 items kar rahe hai. toh double ho raha hai

and exclude ke case main c-Wn-1 ana chahiye kyunki hum kaunsa n-1 vali item include kar rahe hai toh

hello @mittali

jo argument hum function me pass kar rahe hai wo length hai array ki.
intilally n pass kareneg. aur profit access karne ke lie hum n-1 use kareneg kyunki array me values 0 based hai.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.