https://hack.codingblocks.com/contests/c/512/1097
IN THIS I DONT UNDERSTAND THE CORRECTNESS OF LOGIC GIVEN ON GEEKS FOR GEEKS SITE
how by removing the count of till last occurance of some character which was repeated got us the right answer
e.g in this string abca;
the following will be the subsequences generated am just generating so as to analyse the correctness of logic
_ first i have NULL string this is index 0 , dp[0]=1;
‘a’ _ index 1 dp[1]=2*dp[1-1]=2
‘ab’ ‘b’ ‘a’ _
‘abc’ ‘bc’ ‘ac’ ‘c’ ‘ab’ ‘b’ ‘a’ _
now adding a and seeing the repetitions
‘abca’ ‘bca’ ‘aca’ ‘ca’ ‘aba’ ‘ba’ ‘aa’ ‘a’ ‘abc’ ‘bc’ ‘ac’ ‘c’ ‘ab’ ‘b’ ‘a’ _
1…2…3… 4…5…6…7…8…9…10…11…12…13…14…15 …16
repetitions
2 and 9
4 and 11
8 and 15
6 and 13
TOTAL 4
so i need to subtract 4 from the formula dp[i]=2*dp[i-1]; to reduce repetitions and note that 4!=the subsequences of last index i.e dp[1] which is equal to 2
SO THATS WHY I AM FINDING TROUBLE UNDERSTANDING THIS BCOZ I AM ABLE TO FIND A CASES WHERE THIS WILL GET ME WRONG ANS