T-Shirts DP Problem Concept Doubt

So I got the idea that the concepts of this problem is similar to tsp problem.

But I have a doubt on the code that why don’t we write,
ans+=calc(mask,tid+1);
instead we have written the line of code like,
ans= calc(mask,tid+1);
this is the condition when we ignored the current T-Shirt.

hello @Kinjal

both are correct . becuase we have intialise ans with 0.
ans=0 + calc()
or
ans=calc()
both are same

Bhiaya, esa bhi toh ho sakta hai ki branch ke andar yah condition chalega aur uss tym peh ans ka value kuch rahega instead of 0…
Tab inn dono line of code ka value different nhi ayaga kya, bhaiya?

loop ke andar to hamesha ans+= hi rahgea .

usse pehle jab hum current ko ignore kar rahe hai waha pe koi farak nahi padega

Magr, branch ke andar bhi har ek clac() invokation meh start to issi line se hoga na…

nahi cal(mask,tid+1) // ek independent problem ban jayegi na
plus ka koi farak nahi padega

https://drive.google.com/file/d/14cfJiLKdujzreUFwiT9wz4SwutXvWUuy/view?usp=sharing

Bhaiya, Base Case A and Base Case B do branch banaya hai.
Ab base case A peh t-shirt 5 ko ignore kar rhe hai aur fir bhi yah valid case de rha hai…
so 5 ko ignore karne ka condition yahi hai na… ans+=calc(mask,tid+1)

mujhe link ka access do

Abhi dekh pa rhe hai kya?

image

isme batao

Ab base case A peh t-shirt 5 ko ignore kar rhe hai aur yah valid case de rha hai…
so t-shirt 5 ko ignore karne ka condition yahi hai na…
ans =calc(mask,tid+1)?

ha yehi hai … . . …

toh fir, ans+=calc(mask, tid+1) nhi karenge tab, valid case ka count fir 0 se start ho jayega…yhi confusion kr rha hai mujhe…

Kyun ki, ans peh hum valid case ka count store kar rhe hai na?

result tumhara phir upar propagate karega na.
ye line isliye liye to hai
image

ek baar recursion revise kar lo apna.

1 Like

accha…backtrack ke samay ans+ ho rha hai…
so + operator use kare ya na kare iss line peh, koi farak nhi padega…

ha … … …

Thanks Bhaiya. Appreciate your help. Have a great day.

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.

Bhaiya, kr diya.
Ese resolved doubt karne ke tym jo feedback box pop up hota hai, woh kya same nhi hai isswale se…

pata nahi bhai , ye feedback waghera ta ko accessible nahi hai.
maine kabhi iska interface nahi dekha