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.

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

1 | tourist | 3509 |

2 | OO0OOO00O0OOO0O0…O | 3327 |

3 | Syloviaely | 3274 |

4 | Um_nik | 3237 |

5 | Petr | 3161 |

6 | fjzzq2002 | 3137 |

7 | LHiC | 3135 |

8 | Benq | 3130 |

9 | ko_osaga | 3115 |

10 | Swistakk | 3089 |

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

1 | Radewoosh | 185 |

2 | rng_58 | 161 |

3 | tourist | 158 |

4 | Petr | 152 |

5 | Swistakk | 150 |

5 | Vovuh | 150 |

7 | Um_nik | 149 |

8 | PikMike | 147 |

9 | csacademy | 146 |

10 | Errichto | 145 |

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: Sep/25/2018 22:59:41 (f1).

Desktop version, switch to mobile version.

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.