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 | Petr | 3325 |

2 | OO0OOO00O0OOO0O0…O | 3289 |

3 | Um_nik | 3278 |

4 | Syloviaely | 3274 |

5 | tourist | 3206 |

6 | Radewoosh | 3197 |

7 | V--o_o--V | 3167 |

8 | mnbvmar | 3096 |

9 | dotorya | 3086 |

10 | FizzyDavid | 3023 |

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

1 | tourist | 183 |

2 | rng_58 | 168 |

3 | csacademy | 160 |

3 | Petr | 160 |

5 | lewin | 151 |

6 | Swistakk | 150 |

7 | matthew99 | 142 |

8 | BledDest | 141 |

9 | Errichto | 140 |

10 | adamant | 139 |

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: Apr/23/2018 08:59:14 (d3).

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.