Hi guys, Can anyone please help me a bit in understanding this problem?

https://www.geeksforgeeks.org/number-subsequences-form-ai-bj-ck/

I m having difficulty in understanding mainly this part.

Please subscribe to the official Codeforces channel in Telegram via the link: https://t.me/codeforces_official.
×

# | User | Rating |
---|---|---|

1 | tourist | 3469 |

2 | Radewoosh | 3357 |

3 | OO0OOO00O0OOO0O0…O | 3264 |

4 | LHiC | 3227 |

5 | ksun48 | 3184 |

6 | scott_wu | 3168 |

7 | Um_nik | 3166 |

8 | CongLingDanPaiSh…5 | 3157 |

9 | Petr | 3139 |

10 | V--o_o--V | 3135 |

# | User | Contrib. |
---|---|---|

1 | Radewoosh | 195 |

2 | Errichto | 175 |

3 | rng_58 | 158 |

4 | Ashishgup | 157 |

4 | neal | 157 |

6 | tourist | 154 |

7 | PikMike | 152 |

8 | Petr | 151 |

9 | Um_nik | 149 |

10 | kostka | 148 |

Hi guys, Can anyone please help me a bit in understanding this problem?

https://www.geeksforgeeks.org/number-subsequences-form-ai-bj-ck/

I m having difficulty in understanding mainly this part.

↑

↓

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Dec/19/2018 11:45:12 (d1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

I am and will always be thankful to all people who have ever helped me and will help me in coming future.

Thank you from the bottom of my heart.

aCount is the number of subsequences of the letter 'a'.

Consider this example: aa. We can see that aCount for this is 3, because we can choose of these possibilities: (xa,ax,aa) (x means we did not use that character). Note also that this is independent of characters in between, i.e. the aCount of aa and ccbabbbcac are the same because both has exactly 2 a's.

Now, adding 1 a, we now have the following new subsequences: each of the old subsequences, each of the old subsequences + the new a, and the new letter a, alone. So a total of aCount + aCount + 1 subsequences.

Now, let's consider bCount, the number of subsequences with some a's and then some b's. in 'aab', we see that bCount should be 3 (axb,xab,aab), because it is just the number of ways we can choose subsequences of the first two a's, and then b. So every time we add a b, the number of ways increases by aCount.

Let's find bCount for 'aabb'. We have already determined that aab has 3 subsequences, so certainly we still have those. Additionally, we can add the new b onto any of these subsequences, to get 3 more. Finally, we have to count the subsequences that are made without using any other b's, and by the logic in the last paragraph, that is just aCount. So, bCount after this is just the old bCount*2 + aCount;

cCount is similar, and I think you can figure it out from here.