Why is the base case for SUPW problem is
dp[0]= a[0]
,dp[1] = a[1]
,dp[2]=a[2].?
If there was only two elements then we can prefer not to choose at all and hence dp[0]=0 and dp[1]=0. And dp[2] =min(a[0],a[1],a[2]).
Why is the base case for SUPW problem is
dp[0]= a[0]
,dp[1] = a[1]
,dp[2]=a[2].?
If there was only two elements then we can prefer not to choose at all and hence dp[0]=0 and dp[1]=0. And dp[2] =min(a[0],a[1],a[2]).
it is mentioned you have to take atleast one element
hence u cannot go for dp[0] as 0 and dp[1] as zero
for
dp[2] is chosen as a[2] to handle the general case as well
see as soon as dp[3] comes
u will have a choice then whether to take a[0, 1 or 2] but if they are all zero it will always take zero which is not correct and hence these will act as base cases of the function